home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 42 / Amiga Format AFCD42 (Issue 126, Aug 1999).iso / -serious- / hardware / whichamiga / whichamiga.asm < prev    next >
Assembly Source File  |  1999-05-17  |  111KB  |  5,366 lines

  1. ; FILE: Source:WhichAmiga.ASM          REV: 772 --- Identify which Amiga model you're running
  2. ; Hist
  3. ; 0-17    Prehistoric revisions. Working hard(?) 19.7.95.
  4. ;  18     Fixed a bug, it would have caused an enforcer hit under
  5. ;         KS 1.3. ;-)
  6. ;  30     Added Workbench startup.
  7. ;  41     Machine evaluation works.
  8. ;  47     Added more machine formulas about 3.00 AM 20.7.95.
  9. ;  52     Added waterproof A3000 check (ramsey&gary test). Fixed machine
  10. ;         formulas. Fixed CD³² KS version to V40.
  11. ;  57     Added FindConfigDev routine. Added A2500 and A500old.
  12. ;  71     Added all machine formulas.
  13. ;  74     Fixed MMU disable/enable as much as possible.
  14. ;  93     Aaargh! Movec with TC doesn't work! Use pmove.l (an) instead!!
  15. ;  96     GetCPU surrounded with DisableMMU/EnableMMU pair.
  16. ; 97-148  MUCH improved.
  17. ;  149    Added better console output code for running under V37 or better.
  18. ;         CD³² users aren't forced to press return anymore... :- )
  19. ;  183    Added correct 68EC020 test.
  20. ;  197    Added real 68060 test and fixed MMU codes.
  21. ;  214    Fixed 68060 test and MMU codes.
  22. ;  228    Bug?: Sometimes can't disable MMU!?
  23. ;  275    Fixed MMU code a *lot*! Now display is blanked when display doesn't
  24. ;         have 4x bandwidth. Now WhichAmiga works with Enforcer, CPU FASTROM and
  25. ;         VMM etc.
  26. ;  281    Now checks cardslot via hardware.
  27. ;  282    Added test for stock model Walker.
  28. ;  301    Added display for Paula, Ramsey, Gary and Gayle. Now checks IDE
  29. ;         connection via hardware.
  30. ; 302-304 Added DraCo support.
  31. ;  305    A4000 also has Ramsey chip, but no Gary chip! (I guess!)
  32. ;  309    Now should be 100% HW  i ndependent, if needed (DraCo!) 
  33. ;  313    Added display for Akiko.
  34. ;  328    Really fixed GetAddressBits and moved all VMEM critical code
  35. ;         into CODE_C hunk.
  36. ;  331    Real support for DraCo... It wouldn't have worked...
  37. ;  333    Fixed CDTV test.
  38. ;  347    Tried to fix 68040/060 MMU code as much as possible.
  39. ;  364    A3000 and A4000 have both Ramsey and Gary, A4000 has Ramsey rev $F.
  40. ;  371    Few things added/fixed.
  41. ;  377    Fixed bad 040/060 MMU test.
  42. ;  384    Added very flexible CPU/FPU/MMU support.
  43. ;  427    Added support for boards.library and several gfx boards.
  44. ;  459    Rewritten MMU disable/enable code.
  45. ;  462    Added correct 68060 speed index.
  46. ;  466    Added special support for Blizzard boards' MAPROM.
  47. ;  471    Doesn't turn off write allocate... Turns on BERR timeout if Gary
  48. ;         chip is present.
  49. ;  482    Added (hopefully) correct 68040/68060 MMU code.
  50. ;  486    Whops! Turned on BERR not DSACK! :-\
  51. ;  499    Added some extensive debug stuff...
  52. ;  514    Fixed bug in 68040/68060 MMU test code.
  53. ;  512    Finally works with 060 (and 040 too :). Fixed to test bit 15 of
  54. ;         TC in MMU activity test on 040 and 060.
  55. ;  529    Fixed Ramsey&Gary test. Added other graphics systems.
  56. ;  535    Now adjusts comparisation CPU automagically.
  57. ;  538    Fixed A3000 machine formula to accept any ECS agnus.
  58. ;  543    Separated Ramsey and Gary test. Added correct KS 3.2 version
  59. ;         information.
  60. ;  547    Fixed loads of OldOpenLibrary, lea (LibList,a6), (ThisTask,a6)...
  61. ;         Cached SysBase etc.
  62. ;  560    Added SetPatch version info.
  63. ;  561    Fixed CloseLibrary(0) bug. Crashed on pre-36 kickstarts.
  64. ;  562    Added identification for UAE and phase5's PowerUP boards.
  65. ;  566    Added proper identification for PowerUP boards.
  66. ;  569    Added support for GigaMem (Max Virtmem).
  67. ;  578    Fixed "CNOP 0,4 in code" bug.
  68. ;  591    Fiddled a bit with 030 MMU code. Fixed UAE detection. Added
  69. ;         6 new gfxcards. Added display for sound cards. 7 sound cards
  70. ;         detected as of now.
  71. ;  596    Added support for CyberGraphX V3.
  72. ;  608    Fiddled again with 030 MMU code. This time I found a bug from it :)
  73. ;         Also tried to fix Ramsey & Gary code.
  74. ;  616    Fixed A3000/A4000 (=Ramsey&Gary) test (hopefully!)
  75. ;  619    Hopefully _finally_ fixed 030 MMU test for defective 68030 chips.
  76. ;         Thanks to [Angel] for testing!
  77. ;  626    Fixed A4000T rom version.
  78. ;  631    Really fixed A4000 test. For some reason my AGA test required rev
  79. ;         13 Gayle chip to be present. Uh-oh.
  80. ;  632    Fixed A1000 ROM version because it can be changed.
  81. ;  633    Hopefully fixed UAE detection.
  82. ;  644    Defective 68030 MMU test (hopefully) fixed.
  83. ;  645    Added Delfina LITE sound card.
  84. ;  646    retina.library is bad... Added check for Retina boards. Thanks to
  85. ;         Hurtman for the tip.
  86. ;  653    Added hardware clock detection. Suggested by Hurtman.
  87. ;  654    Removed one A500 board from A2000 expboardslist. Removed GVP kludge.
  88. ;  655    Removed two A500/A2000 boards from A500 list. Added one (hopefully)
  89. ;         A2000 only board. Thanks to pyksy.
  90. ;  656    Finally got ppc.library autodocs&includes. Fixed PowerPC CPU version
  91. ;         display.
  92. ;  744    13th May 1998: Made the source public in hope someone would continue
  93. ;         the development. At least you can find some interesting routines from
  94. ;         here. ;)
  95. ;  748    Fixed PPC detection, now support for multiple PPC cpus & fixed 604e
  96. ;         not to show as '?'. Fixed some minor bugs.
  97. ;  753    Fixed pre-SetPatch 060 test.
  98. ;  755    Added brand new 0x0 MHz calculation. Should work well with all 0x0
  99. ;         systems.
  100. ;  760    Fixed some bugs. Added PPL display to ppc processor display. Added
  101. ;         revision display for 060. Added Blizzard PPC serial number display.
  102. ;  762    Added CyberVision PPC to gfxboard list.
  103. ;  772    2nd May 1999: Fixed ppc revision display + now displays busclock MHz
  104. ;         instead of PPL number.
  105. ;
  106.  
  107.     IFGT    0
  108.  
  109. Found this inside ppc.library : =)
  110.  
  111.                         PowerUP                         
  112. Now you hold it in your hands which took a lot sweat,   
  113. internal Phase5 conflicts and the lack of motivation    
  114. devil made his appearance several times during the      
  115. 2 years this project was ...running...                  
  116.  
  117. ...a product which goals were changed several times     
  118. until it was released.                                  
  119.  
  120. PowerUP/Phase5 project history censored and deleted.    
  121.  
  122. ppc.library by Ralph Schmidt                            
  123. SW/HW Debugging and food supply by Gerald Carda         
  124. Debugging,Suggestions and mental support by Frank Mariak
  125. Debugging and some examples by Andre Osterhues          
  126.  
  127. Private Greetings are going to:
  128. Dirk Leschner, Arne Meier, Matthias Scheler and all my  
  129. Innernet-#grapevine friends
  130.  
  131.  
  132.  
  133.  A3000:
  134.  
  135.  CHIPS:
  136.   Denise - 8373 SuperDenise
  137.   Paula  - Standard Paula
  138.   Agnus  - 8372B Agnus for 2 meg CHIP RAM
  139.   Gary   - Fat Gary
  140.   Amber  - De-interlacing chip to provide 31KHz video
  141.   Buster - SuperBuster -07, -09 and -11
  142.   DMAC   - SuperDMAC -02, -04
  143.   Ramsey - Ramsey -04 and -07
  144.  
  145.                           -===- Amiga 4000/040 -===-
  146.  
  147.     Processor : Motorola 68040 / 25Mhz
  148.  Custom Chips : (6): Super Gary, Super Ramsey, Super Amber, Lisa, Alice,
  149.                      Paula.
  150.           RAM : 6mb Ram [2mb Chip/ 4mb Fast]
  151.  
  152.  
  153.     ENDC
  154. ; TODO:
  155. ; o Add CGFX4 BlizzardVision PPC to gfxboard list
  156. ; o Fix FPU speed calculation and enable it
  157. ; o Add WarpOS support
  158. ; o Fix bugs...
  159.  
  160. ; BUGS:
  161. ; o Crashes on GVP 1230!! (works sometimes) ;-((  *KLUDGEFIXED*
  162. ; o No support for:
  163. ; Amber / Super Amber    ECS
  164. ; Buster        Zorro III DMA Controller
  165. ; SuperIO        "Walker project"
  166. ; Super Agnus (8375)    2MB chip PLCC A500+
  167. ; Portia        A1000
  168. ; Daphne        A1000
  169.  
  170. ; Compiling options:
  171.  
  172. WA_USE_INCLUDES    SET    1    ; 0=Use my custom system, 1=Use standard includes
  173. WA_DEBUG    SET    1    ; 0=No debug, 1=Enable debug mode
  174.  
  175.  
  176.  
  177.  
  178.     IFEQ    WA_USE_INCLUDES
  179.     include    "Devpac:Gen.gs"
  180.     ELSE
  181.     include    "exec/memory.i"
  182.     include    "exec/exec_lib.i"
  183.     include    "dos/dos_lib.i"
  184.     include    "libraries/graphics_lib.i"
  185.     IFND    MYMACROS_I
  186. call    MACRO
  187.     jsr (_LVO\1,a6)
  188.     ENDM
  189.     ENDC
  190.     ENDC
  191.     include    "exec/execbase.i"
  192.     include    "libraries/expansion_lib.i"
  193.     include    "libraries/configvars.i"
  194.     include    "libraries/configregs.i"
  195.     include    "dos/dosextens.i"
  196.     include    "graphics/gfxbase.i"
  197.     IFEQ    WA_USE_INCLUDES
  198.     include    "hardware/demo.i"
  199.     ELSE
  200.     include    "hardware/cia.i"
  201.     include    "hardware/custom.i"
  202.     ENDC
  203.     include    "hardware/intbits.i"
  204.     include    "hardware/dmabits.i"
  205. ;    include    "libraries/boards.i"
  206. ;    include    "libraries/boards_lib.i"
  207.  
  208.  
  209.     include    "powerup/ppclib/ppc.i"
  210. _LVOPPCGetInfo    EQU    -$8A
  211.  
  212.     IFND    _LVOBestCModeIDTagList
  213. _LVOBestCModeIDTagList    EQU    -$3C
  214.     ENDC
  215.     IFND    CYBRBIDTG_MONITORID
  216. CYBRBIDTG_MONITORID    EQU    $80050003
  217.     ENDC
  218.  
  219.  
  220.     IFND    ciacra
  221. ciapra    EQU    PRA
  222. ciaprb    EQU    PRB
  223. ciaddra    EQU    DDRA
  224. ciaddrb    EQU    DDRB
  225. ciatalo    EQU    TALO
  226. ciatahi    EQU    TAHI
  227. ciatblo    EQU    TBLO
  228. ciatbhi    EQU    TBHI
  229. ciatodlow    EQU    TODLO
  230. ciatodmid    EQU    TODMID
  231. ciatodhi    EQU    TODHI
  232. ciasdr    EQU    SDR
  233. ciaicr    EQU    ICR
  234. ciacra    EQU    CRA
  235. ciacrb    EQU    CRB
  236.     ENDC
  237.     IFND    CIAB
  238. CIAB    EQU    $BFD000
  239.     ENDC
  240.     IFND    AFB_68060
  241. AFB_68060    EQU    7
  242. AFF_68060    EQU    1<<AFB_68060
  243.     ENDC
  244. _LVOAddICRVector EQU    -$6
  245. _LVORemICRVector EQU    -$C
  246. _LVOAbleICR    EQU    -$12
  247. _LVOSetICR    EQU    -$18
  248.  
  249. _LVOFreeNVData    EQU    -$24
  250. _LVOGetNVInfo    EQU    -$36
  251.  
  252. INFINITE    EQU    $7FFFFFFF
  253. MINUS_INFINITE    EQU    $80000000
  254.  
  255. ID_UNIX_DISK    EQU    ('U'<<24)!('N'<<16)!('I'<<8)!(1)
  256.  
  257.  
  258. MC68000    EQU    0
  259. MC68010    EQU    1
  260. MC68EC020    EQU    2    24bit ab
  261. MC68020    EQU    3    32bit ab
  262. MC68EC030     EQU    4    no mmu
  263. MC68030    EQU    5    mmu
  264. MC68EC040     EQU    6    no mmu, no fpu
  265. MC68LC040     EQU    7    mmu, no fpu
  266. MC68040    EQU    8    mmu, fpu
  267. MC68EC060     EQU    9    no mmu, no fpu
  268. MC68LC060     EQU    10    mmu, no fpu
  269. MC68060    EQU    11    mmu, fpu
  270.  
  271. ;;MPC603e    EQU    12    \
  272. ;;MPC604    EQU    13     } not yet implemented, but supported
  273. ;;MPC620    EQU    14    /
  274.  
  275.  
  276. MIN020    EQU    MC68EC020
  277. MAX020    EQU    MC68020
  278. MIN030    EQU    MC68EC030
  279. MAX030    EQU    MC68030
  280. MIN040    EQU    MC68EC040
  281. MAX040    EQU    MC68040
  282. MIN060    EQU    MC68EC060
  283. MAX060    EQU    MC68060
  284. MAXCPU    EQU    INFINITE
  285.  
  286. NOMATH    EQU    0
  287. MC68881    EQU    1
  288. MC68882    EQU    2
  289. MC68040i    EQU    3
  290. MC68060i    EQU    4
  291. MINFPU    EQU    MC68881
  292. MAXFPU    EQU    INFINITE
  293.  
  294. NOMMU    EQU    0
  295. MC68851    EQU    1
  296. MC68030m    EQU    2
  297. MC68040m    EQU    3
  298. MC68060m    EQU    4
  299. MINMMU    EQU    MC68851
  300. MAXMMU    EQU    INFINITE
  301.  
  302. DBG    MACRO    *id
  303.     IFNE    WA_DEBUG
  304.     move.l    #\1,-(sp)
  305.     jsr    _dp
  306.     ENDC
  307.     ENDM
  308.     IFNE    WA_DEBUG
  309. _DBUGMAIN    jmp    __MAIN
  310. _dp    bra.b    .exit
  311.     btst    #INTB_INTEN-8,$DFF000+intenar
  312.     beq.b    .exit
  313.     btst    #INTB_PORTS,$DFF000+intenar+1
  314.     beq.b    .exit
  315.     movem.l    d0-a6,-(sp)
  316.     move.l    (4).w,a6        No need...
  317.     clr.l    -(sp)
  318.     move.l    (8*4+7*4+4+4,sp),-(sp)
  319.     move.l    sp,-(sp)
  320.     lea    (LibList,a6),a0        No need...
  321.     lea    (.dosname,pc),a1
  322.     call    FindName
  323.     move.l    d0,a6
  324.     lea    (.fmt,pc),a0
  325.     move.l    a0,d1
  326.     addq.l    #1,-(a0)
  327.     move.l    (a0),-(sp)
  328.     move.l    sp,d2
  329.     call    VPrintf
  330.     call    Output
  331.     move.l    d0,d1
  332.     call    Flush
  333.     moveq    #10,d1
  334.     call    Delay
  335.     lea    (4*4,sp),sp
  336.     movem.l    (sp)+,d0-a6
  337. .exit    move.l    (sp)+,(sp)
  338.     rts
  339.     CNOP    0,4
  340. .cnt    dc.l    0
  341. .fmt    dc.b    'DEBUG %ld: %4s',10,0
  342. .dosname    dc.b    'dos.library',0
  343.  
  344.     SECTION    DREALMAIN,CODE
  345.     ENDC
  346. __MAIN
  347.  
  348.     IFGT    0
  349.     lea    (.init,pc),a0
  350.     lea    (.rout,pc),a1
  351.     lea    (.cleanup,pc),a2
  352.     jsr    TimeRoutine
  353.     rts
  354.  
  355. .init    move.l    (4).w,a6
  356.     call    Disable
  357.     rts
  358. .rout    move.l    #$1000,d0
  359. .loop    subq.l    #1,d0
  360.     bne.b    .loop
  361.     rts
  362. .cleanup    move.l    (4).w,a6
  363.     call    Enable
  364.     rts
  365.     ENDC
  366.  
  367. ;    include    "Source:WBStartUp.ASM"
  368.  
  369. ; WBStartUp code
  370.  
  371. startupcode    move.l    (4).w,a6
  372.     move.l    d0,d2
  373.     move.l    a0,a2
  374.     sub.l    a1,a1
  375.     jsr    (-$126,a6)    ;FindTask
  376.     move.l    d0,a4
  377.  
  378.     tst.l    ($AC,a4)    ; pr_CLI
  379.     bne.s    .main
  380.  
  381.     lea    ($5C,a4),a0    ; pr_MsgPort
  382.     jsr    (-$180,a6)    ;WaitPort
  383.     lea    ($5C,a4),a0    ; pr_MsgPort
  384.     jsr    (-$174,a6)    ;GetMsg
  385.     move.l    d0,-(sp)
  386.     sub.l    a0,a0
  387.     bsr.b    .main
  388.     move.l    d0,d2
  389.  
  390.     move.l    (4).w,a6
  391.     jsr    (-$84,a6)    ;Forbid
  392.     move.l    (sp)+,a1
  393.     jsr    (-$17A,a6)    ;ReplyMsg
  394.  
  395.     move.l    d2,d0
  396.     rts
  397.  
  398. .main    move.l    d2,d0
  399.     move.l    a2,a0
  400.     ; a6=execbase
  401.     ; a4=thistask (FindTask()'d! :)
  402.  
  403.  
  404. MAINMAIN    clr.b    -1(a0,d0.l)
  405.     move.l    a0,_Args
  406.     move.l    a4,_ThisTask
  407.     lea    (ExecBase00,pc),a0
  408.     move.l    a6,(a0)
  409.     lea    (__MAIN-4,pc),a0
  410. .eloop    move.l    (a0),d0
  411.     beq.b    .edone
  412.     lsl.l    #2,d0
  413.     move.l    d0,a0
  414.     move.l    a6,(4,a0)
  415.     bra.b    .eloop
  416. .edone
  417.     tst.l    (pr_CLI,a4)
  418.     seq    WBMode
  419.     cmp.w    #36,(LIB_VERSION,a6)
  420.     shi    NewKick
  421.  
  422.     IFNE    WA_DEBUG
  423.     cmp.w    #37,(LIB_VERSION,a6)
  424.     blo.b    .db_exit
  425.     tst.b    WBMode
  426.     bne.b    .db_exit
  427.     move.l    _Args,a0
  428.     tst.b    (a0)
  429.     beq.b    .db_exit
  430.     move.w    #$4E71,_dp        Enable debug stuff!
  431.     call    CacheClearU
  432. .db_exit
  433.     ENDC
  434.  
  435.     lea    (DosName,pc),a1
  436.     moveq    #0,d0
  437.     call    OpenLibrary
  438.     move.l    d0,_DosBase
  439.     beq.b    .fail
  440.     move.l    d0,a5
  441.  
  442.     exg    a5,a6
  443.     call    Output
  444.     tst.b    WBMode
  445.     bpl.b    .cli
  446.     lea    (ConsoleName,pc),a0
  447.     tst.b    NewKick
  448.     bpl.b    .is_old
  449.     lea    (NewConsoleName-ConsoleName,a0),a0
  450. .is_old    move.l    a0,d1
  451.     move.l    #MODE_READWRITE,d2
  452.     call    Open
  453. .cli    move.l    d0,OutputFH
  454.     exg    a5,a6
  455.     bne.b    .gotfh
  456. .fail    moveq    #RETURN_FAIL,d0        <- Things are badly wrong!
  457.     rts
  458. .gotfh
  459.  
  460.  IFGT 0
  461.                         Agnus    PCMCIA  Akiko   AT-IDE    NVRAM  Ramsey&Gary
  462.             KS:     Denise    Chip   A690ID  Proc   StockMHz   UNI/01   A26x0
  463. >A1000   1.1-1.3      O Older  ¼/½          01??      7
  464. >A500old 1.2-2.x,3.1  O  Old   ½            01234     7
  465.  A500    1.2-2.x,3.1  O  Fat   ½-2          01234     7
  466.  A500+   2.x,3.1      E Super  1-2          01234     7
  467. >CDTV    1.3,2.x,3.1? O ?Fat?  1   (x) x    01234     7
  468. >A600    2.05,3.1     E Fatter 1/2  x       0  3    x 7
  469. >A1200*  3.0,3.1      A  AGA   1/2  x         2346p x 14
  470. >A1400   3.0,3.1      A  AGA   1/2  x         2??   x 25/28
  471. >CD³²    3.1          A  AGA   2          x   23    x 14     x
  472.  A2000   1.2-2.x,3.1  O  Fat   ½/1          012346p   7
  473.  A2000+  1.2-2.x,3.1  E  Fat   ½/1          012346p   7
  474. >A2500   1.2-2.x,3.1  O  Fat   ½/1            23      25                  x
  475. >A3000   1.3/2.x,3.1  E Ftr/Sp 1/2             346p   16/25/30         x
  476. >A3000UX UNIX         E Ftr/Sp 1/2             346p   25        x      x
  477. >A4000   3.0,3.1      A  AGA   2               346p x '30/25           x
  478.  A4000T* 3.1          A  AGA   2                46p x '40/25           x
  479. XWalker* 3.2          A  AGA   1/2             3  p x 'EC30/40
  480. >DraCo   AmigaOS      -   -     -                6?   50
  481.  
  482. * Amiga 3000 has always MMU and math co-processor. (?)
  483. * Blizzard turbos can have Kickstart ROM ReKicked 100% transparently, so
  484.   any kickstart version goes!
  485. * Amiga 3000 Tower has a HD floppy drive by default?
  486. * Amiga 4000 Tower has 68040 @ 25 MHz or 68060 @ 50 MHz, AmigaOS 3.1 and
  487.   SCSI-II controller (built in, not A4091?)
  488. X Walker has a SuperIO chip.
  489. * Draco has Altais gfx card. (see rs:identify.library.rs)
  490.  
  491.  
  492.  Check PCMCIA: Find 'card.resource'    600/1200/(570?)
  493.  Check CDTV: Find 'cdtv.device'
  494.  Check A690ID: FindResident 'A690ID'   570  (A500 CD-ROM/CDTV expansion)
  495.  Check AT-IDE: Find interrupt 'AT-IDE' 600/1200/4000
  496.  Check Akiko: Test GfxBase.ChunkyToPlanarPtr CD³² [OR HW emul card]
  497.  Check NVRAM: Test Nonvolatile/GetNVInfo() maxstorage
  498.  Check UNIX: Find any bootable UNI/01 partition
  499.  Check A3000: Ramsey-Chip rev < $F  (that is $D)
  500.  Check A4000: Ramsey-Chip rev >= $F
  501.  Check A2500: Match ConfigDev for A2620/A2630 turbo card
  502.  Check DraCo: Find 'draco.resource'
  503.  Check UAE: FindName(execbase.intrlist,'UAE filesystem')
  504.  
  505.  ROM:
  506.                                                       || 256 KB
  507.      30: 1000old with KS1.0                           \/
  508.      31: 1000 with KS 1.1 ntsc
  509.      32: 1000 with KS 1.1 pal
  510.   33 34: All but  1200, 4000, CD³², 500+, 600
  511.      35: Beta, not in chip                            ||
  512.      36: Early 3000                                   \/ 512 KB
  513.      37: All but 1000[old], 1200, 4000, CD³²
  514.      38: Not in chip
  515.      39: A1200, A1400, A4000
  516.      40: All but A1000[old]
  517.      41: Not in chip
  518.      42: Not in chip
  519. X    43: Walker (AmigaOS 3.2)                        || 1024 KB
  520.                                                      \/
  521.  
  522.     - Agnus Hardware Stats -
  523.  
  524.                         MODEL   VIDEO    CHIPRAM         CHIP TYPE
  525.         Agnus           8361    NTSC       512k     A1000 Subsystem DIP
  526.         Agnus           8361    NTSC       512k     A1000 Subsystem DIP
  527.         Fat Agnus       8370    NTSC       512k     DIP
  528.         Fat Agnus       8370    NTSC       512k     PLCC
  529.         Fat Agnus       8371    PAL        512k     DIP
  530.         Fat Agnus       8371    PAL        512k     PLCC
  531.         Fat Agnus       8372    NTSC/PAL   512k     PLCC
  532.         Fatter Agnus    8372a   NTSC/PAL  1024k     PLCC
  533.         Super Agnus     8372b   NTSC/PAL  2048k     PLCC A3000
  534.         Super Agnus     8375    NTSC/PAL  2048k     PLCC A500+
  535.         Alice                   NTSC/PAL  2048k     PLCC A4000/A1200
  536.  
  537.  
  538.   Question: Why doesn't SCSI work on the A4000?
  539.     Answer: It does. But because of a bug in early versions of the Zorro-III
  540.             DMA controller (the "Buster" chip), DMA SCSI controllers didn't
  541.             work properly. This problem can be fixed (by replacing the early
  542.             revision 9 Buster with a revision 11 version) or avoided
  543.             altogether (by using a SCSI controller that doesn't use the
  544.             Zorro-III bus, like the one built into the Warp Engine
  545.             accelerator).
  546.  
  547.  ENDC
  548.  
  549.     movem.l    a4/a5,-(sp)
  550.     bsr.b    __Main
  551.     movem.l    (sp)+,a4/a5
  552.     move.l    d0,-(sp)
  553.  
  554.     lea    (CursorOn,pc),a0
  555.     bsr    Printf
  556.  
  557.     tst.b    WBMode
  558.     bpl.b    .cli_noclose
  559.  
  560.     move.l    a5,a6
  561.  
  562.     tst.b    NewKick
  563.     bmi.b    .close_up
  564.  
  565.     lea    (PressReturn,pc),a0
  566.     bsr    Printf
  567.  
  568.     subq.l    #4,sp
  569.     move.l    OutputFH,d1
  570.     move.l    sp,d2
  571.     moveq    #1,d3
  572.     call    Read
  573.     addq.l    #4,sp
  574.  
  575. .close_up    move.l    OutputFH,d1
  576.     call    Close
  577. .cli_noclose
  578.     move.l    (ExecBase00,pc),a6
  579.     move.l    _DosBase,a1
  580.     call    CloseLibrary
  581.  
  582.     move.l    (sp)+,d0
  583.     rts
  584.  
  585.  
  586. _error    moveq    #RETURN_ERROR,d0
  587.     rts
  588.  
  589. __Main
  590.     DBG    'bgma'
  591.  
  592.     move.l    (4).w,a6        Use (4).w
  593.     bsr    GetDraCo
  594.  
  595.     DBG    'gdra'
  596.  
  597.  
  598.     bsr    ExtAttnFlags
  599.     move.w    d0,_AttnFlags
  600.  
  601.     DBG    'gatf'
  602.  
  603.     jsr    CacheClearU        Clear caches (now ExecBaseXX are valid)
  604.  
  605.     DBG    'cacc'
  606.  
  607.     lea    (_GfxName,pc),a1
  608.     moveq    #0,d0
  609.     call    OpenLibrary
  610.     move.l    d0,_GfxBase
  611.     beq    _error
  612.     move.l    d0,a1
  613.     call    CloseLibrary
  614.     lea    (ExpName,pc),a1
  615.     moveq    #0,d0
  616.     call    OpenLibrary
  617.     move.l    d0,_ExpBase
  618.     beq    _error
  619.     move.l    d0,a1
  620.     call    CloseLibrary
  621.  
  622.     lea    (sStart,pc),a0
  623.     bsr    Printf
  624.  
  625.     DBG    'seva'
  626.  
  627.     st    RamseyRev
  628.     move.w    _AttnFlags,d0
  629.     bsr    GetRamsey
  630.  
  631. ;    move.w    #15,d0            debug
  632.  
  633.     beq.b    .no_ramsey
  634.     move.w    d0,RamseyRev
  635.     cmp.w    #15,d0
  636.     slo    A3000ID
  637.     shs    A4000ID
  638. .no_ramsey
  639.     DBG    'gram'
  640.  
  641.     st    GaryRev
  642.     move.w    _AttnFlags,d0
  643.     bsr    GetGary
  644.  
  645. ;    move.w    #0,d0            debug
  646. ;    moveq    #1,d1
  647.  
  648.     beq.b    .no_gary
  649.     move.w    d0,GaryRev
  650.     call    Disable
  651.     move.b    $00DE0000,_wasDSACK
  652.     bpl.b    .is_DSACK
  653.     bclr    #7,$00DE0000        Set DSACK mode...
  654. .is_DSACK    call    Enable
  655. .no_gary
  656.     tst.b    A3000ID            A3000 must have both!
  657.     beq.b    .no_a30gry
  658.     tst.w    RamseyRev
  659.     bpl.b    .no_a30gry
  660.     clr.b    A3000ID
  661. .no_a30gry
  662.  
  663.     DBG    'ggry'
  664.  
  665.     lea    (sMMUna,pc),a0
  666.     move.l    a0,MMU
  667.     lea    (sNullStr,pc),a0
  668.     move.l    a0,MMUStatus
  669.     btst    #AFB_68030,_AttnFlags+1
  670.     beq.b    .lowpros
  671.     st    _EC
  672. .lowpros    jsr    GetMMU
  673.     move.l    d0,_MMUID
  674.     beq.b    .nommu            is 'EC' model
  675.     lea    (sNotActiveStr,pc),a0
  676.     tst.l    d1
  677.     beq.b    .msetoff
  678.     lea    (sRunningStr,pc),a0
  679. .msetoff    move.l    a0,MMUStatus
  680.     lea    (MMUTable,pc),a0
  681.     lea    MMU,a1
  682.     subq.l    #1,d0
  683.     bsr    PutWStrPtr
  684.     clr.l    EC
  685.     clr.l    _EC
  686. .nommu
  687.     DBG    'gmmu'
  688.  
  689.     bsr    GetGayle
  690.     move.w    d0,GayleRev
  691.     cmp.w    #13,d0
  692.     seq    AGAGayleID
  693.     bsr    GetPaula
  694.     move.w    d0,PaulaRev
  695.  
  696.     DBG    'ggay'
  697.  
  698.     bsr    GetGfxChip
  699.     move.b    d0,GfxChipID+3
  700.     move.w    d1,GfxChipRev
  701.     lea    (GfxChipTable,pc),a0
  702.     lea    GfxChip,a1
  703.     bsr    PutWStrPtr
  704.     lea    GChipRevBuffer,a2
  705.     move.l    a2,GfxChipRev_ptr
  706.     lea    (sRev,pc),a0
  707.     lea    GfxChipRev,a1
  708.     move.w    (a1),d0
  709.     bmi.b    .is_OCS
  710.     bsr    Sprintf
  711. .is_OCS
  712.     DBG    'ggcp'
  713.  
  714.     bsr    GetAnimChip
  715.     move.b    d0,AnimChipID+3
  716.     lea    (AnimChipTable,pc),a0
  717.     lea    AnimChip,a1
  718.     bsr    PutWStrPtr
  719.  
  720.     DBG    'gacp'
  721.  
  722.     bsr    GetGfxLibEmul
  723.     move.l    d0,GfxLibEmul
  724.     move.w    d1,BandWidth
  725.     lea    (GfxLibEmulTable,pc),a0
  726.     lea    GfxLibEmul_ptr,a1
  727.     bsr    PutWStrPtr
  728.     lea    DBWBuffer,a2
  729.     move.l    a2,BandWidth_ptr
  730.     cmp.w    #2,GfxLibEmul+2        AGA?
  731.     bne.b    .not_aga
  732.     lea    (sDBWFmt,pc),a0
  733.     lea    BandWidth,a1
  734.     bsr    Sprintf
  735. .not_aga
  736.     DBG    'ggbe'
  737.  
  738.     jsr    GetCPU
  739.  
  740.     DBG    'gcpu'
  741.  
  742.     jsr    GetProcInfo
  743.  
  744.     DBG    'gpin'
  745.  
  746.     move.l    _100kHz,d0
  747.     divu.w    #10,d0
  748.     swap    d0
  749.     move.l    d0,MHz
  750.     move.l    CPUID,d0
  751.     lea    (CPUTable,pc),a0
  752.     lea    CPU,a1
  753.     bsr    PutWStrPtr
  754.  
  755.  
  756.     bsr    GetMisc
  757.  
  758.     DBG    'gmsc'
  759.  
  760.     tst.b    CardSlotID
  761.     bne.b    .has_slot
  762.     bsr    GetCardSlot
  763.     move.b    d0,CardSlotID
  764.  
  765.     DBG    'gcsl'
  766. .has_slot
  767. ;    clr.l    CardSlotID        debug
  768.  
  769.     lea    (sNullStr,pc),a0
  770.     tst.l    UAEID
  771.     beq.b    .nouae
  772.     lea    (sUAE,pc),a0
  773. .nouae    move.l    a0,AfterMG_ptr
  774.  
  775.     lea    (sNA,pc),a0
  776.     tst.l    HWClockID
  777.     beq.b    .nohwclock
  778.     lea    (sClockFound,pc),a0
  779. .nohwclock    move.l    a0,HWClock_ptr
  780.  
  781.  
  782.     tst.b    ATIDEID
  783.     bne.b    .has_ATIDE
  784.     bsr    GetATIDE
  785.     move.b    d0,ATIDEID
  786.  
  787.     DBG    'gide'
  788. .has_ATIDE
  789.  
  790.     lea    (sFna,pc),a2
  791.     move.w    _AttnFlags,d0
  792.     bsr    GetFPU
  793.     move.b    d0,FPUID+3
  794.     beq.b    .nofpu
  795.  
  796.     IFGT    0
  797.     move.l    FPUCompareTime,-(sp)    dbug
  798.     lsr.l    #8,d0
  799.     lsr.l    #8,d0
  800.     divu.w    #10,d0
  801.     swap    d0
  802.     move.l    d0,-(sp)
  803.     lea    (FPUTable,pc),a0
  804.     move.l    FPUID,d0
  805.     add.l    d0,d0
  806.     add.w    (a0,d0.l),a0
  807.     move.l    a0,-(sp)
  808.     lea    (sFPUFmt,pc),a0
  809.     move.l    sp,a1
  810.     lea    FPUBuffer,a2
  811.     bsr    Sprintf
  812. ;;    addq.l    #8,sp
  813.     lea    (3*4,sp),sp        dbug
  814. .nofpu    move.l    a2,FPU_ptr
  815.     ELSE
  816.  
  817.     lea    (FPUTable,pc),a0
  818.     move.l    FPUID,d0
  819.     add.l    d0,d0
  820.     add.w    (a0,d0.l),a0
  821.     move.l    a0,-(sp)
  822.     lea    (sFPUFmt,pc),a0
  823.     move.l    sp,a1
  824.     lea    FPUBuffer,a2
  825.     bsr    Sprintf
  826.     addq.l    #4,sp
  827. .nofpu    move.l    a2,FPU_ptr
  828.     ENDC
  829.  
  830.     DBG    'gfpu'
  831.  
  832.  
  833.     tst.l    A4000ID
  834.     beq.b    .not_a4000t
  835.     move.b    A4091ID,A4000TID    A4091 is checked in GetMisc subr
  836. .not_a4000t
  837.     bsr    GetGfxBoards
  838.     DBG    'ggbo'
  839.  
  840.     bsr    GetSndCards
  841.     DBG    'gsca'
  842.  
  843.     bsr    GetExpBoards
  844.     DBG    'gebo'
  845.  
  846.     bsr    GetChipMem
  847.     move.l    d0,ChipMemd
  848.     move.l    (ExecBase00,pc),a6
  849.     move.l    (MaxLocMem,a6),d0
  850.     lsr.l    #8,d0            /10
  851.     lsr.l    #2,d0
  852.     move.l    d0,ChipMem
  853.  
  854.     DBG    'gcme'
  855.  
  856.     bsr    GetFastMem
  857.     move.l    d0,FastMem
  858.  
  859.     DBG    'gfme'
  860.  
  861.     lea    (sNullStr,pc),a0
  862.     move.l    a0,VirtMem_ptr
  863.     bsr    GetVirtMem
  864.     move.l    d0,VirtMem
  865.     beq.b    .novirtmem
  866.     lea    sVirtMemBuf,a2
  867.     move.l    a2,VirtMem_ptr
  868.     lea    (sVirtMemFmt,pc),a0
  869.     lea    VirtMem,a1
  870.     bsr    Sprintf
  871. .novirtmem
  872.     DBG    'gvme'
  873.  
  874.     move.w    _AttnFlags,d0
  875.     bsr    GetChipRomVer
  876.     move.l    d0,RomVer
  877.     move.l    d1,RomChkSum
  878.     bsr    GetKickStr
  879.     move.l    d0,RomVerS
  880.  
  881.     DBG    'gcro'
  882.  
  883.     bsr    GetCRomVer
  884.     move.l    d0,CRomVer
  885.     move.l    d1,CRomChkSum
  886.     bsr    GetKickStr
  887.     move.l    d0,CRomVerS
  888.  
  889.     DBG    'grom'
  890.  
  891.     lea    (sNullStr,pc),a2
  892.     move.l    RomVer,d0
  893.     cmp.l    CRomVer,d0
  894.     bne.b    .rekickrom
  895.     move.l    RomChkSum,d0
  896.     cmp.l    CRomChkSum,d0
  897.     beq.b    .rom_is_same
  898. .rekickrom    lea    sROMBuf,a2
  899.     lea    (sReKickROM,pc),a0
  900.     lea    CRomVer,a1
  901.     bsr    Sprintf
  902. .rom_is_same    move.l    a2,ReKickROM_ptr
  903.  
  904.  
  905.     bsr    GetWBVersion
  906.     move.l    d0,WBVer
  907.     bsr    GetWBStr
  908.     move.l    d0,WBVerS
  909.  
  910.     DBG    'gwbv'
  911.  
  912.     lea    (sNoSetPatch,pc),a0
  913.     move.l    a0,SetPatchVerPtr
  914.     bsr    GetSetPatchVersion
  915.     tst.l    d0
  916.     beq.b    .nosetpatch
  917.     move.l    d0,-(sp)
  918.     lea    sSetPatchBuf,a2
  919.     lea    (sSetPatchVerFmt,pc),a0
  920.     move.l    sp,a1
  921.     bsr    Sprintf
  922.     move.l    a2,SetPatchVerPtr
  923.     addq.l    #4,sp
  924. .nosetpatch
  925.     DBG    'gspv'
  926.  
  927.     lea    ExpBoardsBuffer,a0
  928.     move.l    a0,ExpBoards_ptr
  929.     bsr    GetBoards
  930.  
  931.     DBG    'gboa'
  932.  
  933.     bsr    GetOtherChips
  934.  
  935.     DBG    'goth'
  936.  
  937.     bsr    EvaluateFormulas
  938.     move.l    d0,MachineGuess
  939.  
  940.     DBG    'deva'
  941.  
  942.     lea    (sRaport,pc),a0
  943.     lea    Params,a1
  944.     bsr    Printf
  945.  
  946.     DBG    'prnt'
  947.  
  948.     tst.w    GaryRev
  949.     bmi.b    .nogary
  950.     call    Disable
  951.     tst.b    _wasDSACK
  952.     bpl.b    .was_DSACK
  953.     bset    #7,$00DE0000        Set BERR if it was on originally!
  954. .was_DSACK    call    Enable
  955. .nogary
  956.     moveq    #RETURN_OK,d0
  957.     rts
  958.  
  959.  
  960. PutWStrPtr    add.w    d0,d0
  961.     add.w    (a0,d0.w),a0
  962.     move.l    a0,(a1)
  963.     rts
  964.  
  965.  
  966. ;  IN: a0=buffer
  967. GetBoards    movem.l    d0-a6,-(sp)
  968.     move.l    a0,a4
  969.     move.l    (ExecBase00,pc),a6
  970.     lea    (.boardsname,pc),a1
  971.     moveq    #2,d0
  972.     call    OpenLibrary
  973.     move.l    d0,d7
  974.     beq    .exit
  975.  
  976.     move.l    d7,a6
  977.     moveq    #0,d0
  978.     jsr    (-36,a6)        call    AllocBoardInfo
  979.     move.l    d0,d6
  980.     beq    .closeboards
  981.  
  982.     moveq    #-1,d0            Any boards available?
  983.     bsr    FindConfigDev
  984.     beq    .noboards
  985.     lea    (.expansion,pc),a0
  986. .copy    move.b    (a0)+,(a4)+
  987.     bne.b    .copy
  988.     subq.l    #1,a4
  989.     sub.l    a1,a1
  990.  
  991. .next    move.l    d6,a0
  992.     jsr    (-42,a6)        call    NextBoardInfo
  993.     tst.l    d0
  994.     beq.b    .done
  995.  
  996.     move.l    d0,-(sp)
  997.     move.l    (16,a0),-(sp)        bi_ExSize
  998.     move.l    (12,a0),-(sp)        bi_ExAddress
  999.     move.l    (32,a0),-(sp)        bi_ProdName
  1000.     move.l    (28,a0),-(sp)        bi_ManuName
  1001.     move.l    (24,a0),-(sp)        bi_ProdID
  1002.     move.l    (20,a0),-(sp)        bi_ManuID
  1003.     move.l    sp,a1
  1004.     lea    (.boardsfmt,pc),a0
  1005.     move.l    a4,a2
  1006.     bsr    Sprintf
  1007.     lea    (6*4,sp),sp
  1008. .findend    tst.b    (a4)+
  1009.     bne.b    .findend
  1010.     subq.l    #1,a4
  1011.  
  1012.     move.l    (sp),a0
  1013.     cmp.w    #$2140,(cd_Rom+er_Manufacturer,a0)    Blizzard PPC?
  1014.     bne.b    .not_blizppc
  1015.     cmp.b    #110,(cd_Rom+er_Product,a0)
  1016.     bne.b    .not_blizppc
  1017.     cmp.w    #$00F0,(cd_BoardAddr,a0)
  1018.     bne.b    .not_blizppc
  1019.     lea    (.blizzppc,pc),a0
  1020.     pea    $F00010
  1021.     move.l    sp,a1
  1022.     move.l    a4,a2
  1023.     bsr    Sprintf
  1024.     addq.l    #4,sp
  1025. .blfindend    tst.b    (a4)+
  1026.     bne.b    .blfindend
  1027.     subq.l    #1,a4
  1028.  
  1029. .not_blizppc
  1030.     move.l    (sp)+,a1
  1031.     bra.b    .next
  1032. .done
  1033. .noboards
  1034. .freebi    move.l    d6,a0
  1035.     jsr    (-48,a6)        call    FreeBoardInfo
  1036. .closeboards    move.l    d7,a1
  1037.     move.l    (ExecBase00,pc),a6
  1038.     call    CloseLibrary
  1039. .exit    movem.l    (sp)+,d0-a6
  1040.     rts
  1041.  
  1042. .boardsname    dc.b    'boards.library',0    BOARDSNAME
  1043. .expansion    dc.b    '     Expansion board(s):',10,0
  1044. .boardsfmt    dc.b    '%s/%s: %s %s (@%s %s)',10,0
  1045. .blizzppc    dc.b    '          Blizzard PPC serial number: %7s',10,0
  1046.     CNOP    0,4
  1047.  
  1048.  
  1049. GetExpBoards    movem.l    d0-d1/a0-a1,-(sp)
  1050.     lea    (ExpBoardTable1,pc),a0    If you have A2000 you propably
  1051. .loop1    move.l    (a0)+,d0        have some expansion stuff in it!!
  1052.     beq.b    .done1
  1053.     bsr    FindConfigDev
  1054.     sne    A2000EID
  1055.     bne.b    .done1
  1056.     bra.b    .loop1
  1057. .done1
  1058.     lea    (ExpBoardTable2,pc),a0    If any A500 expansion is found
  1059. .loop2    move.l    (a0)+,d0        A2000ID is cleared.
  1060.     beq.b    .done2
  1061.     bsr    FindConfigDev
  1062.     beq.b    .loop2
  1063.     st    A500EID
  1064.     clr.b    A2000EID
  1065. .done2
  1066.  
  1067.     tst.l    A690ID
  1068.     beq.b    .no_A500_CDROM
  1069.     st    A500EID
  1070.     clr.b    A2000EID
  1071. .no_A500_CDROM
  1072.     movem.l    (sp)+,d0-d1/a0-a1
  1073.     rts
  1074.  
  1075. ;;; ExpBoardTables
  1076.  
  1077. EXPBRD    MACRO
  1078.     dc.l    ($\1<<16)!\2
  1079.     ENDM
  1080.  
  1081.     CNOP    0,4
  1082. ExpBoardTable2
  1083.     EXPBRD    202,32    A560 Memory Module
  1084.     EXPBRD    3F2,68    MicroBotics VXL RAM*32
  1085.     EXPBRD    3F2,69    MicroBotics VXL 68030 turbo
  1086.     EXPBRD    420,5    Supra 500 HD/RAM interface
  1087.     EXPBRD    420,9    Supra 500XP
  1088.     EXPBRD    420,12    Supra 500XP/Wordsync
  1089.     EXPBRD    420,13    Supra 500XP/Wordsync
  1090. ;500/2000!!!    EXPBRD    7E1,10    GVP Series II (A500) memory board
  1091. ;500/2000!!!    EXPBRD    7E1,11    GVP Series II (A500) SCSI ctrl
  1092.     EXPBRD    801,4    BSC Oktagon 500
  1093.     EXPBRD    82C,4    BSC Oktagon 500
  1094.     EXPBRD    2062,1    Expansion Systems DataFlyer 500 HD Ctrl
  1095.     dc.l    0
  1096.  
  1097.     CNOP    0,4
  1098. ExpBoardTable1
  1099.     ;Harlequin
  1100.     EXPBRD    851,1    Resolver
  1101.     EXPBRD    0851,2    Vivid 24
  1102.     EXPBRD    07E1,68    Rembrandt
  1103.     EXPBRD    0845,2    Visiona
  1104.     ;OpalVision
  1105.     EXPBRD    838,0    FireCracker
  1106.     EXPBRD    838,1    FireCracker
  1107.     EXPBRD    406,0    Lowell A2410
  1108.     EXPBRD    3EC,245    Kronos/C Ltd A2410
  1109.  
  1110.     EXPBRD    0891,1    EGS
  1111.     EXPBRD    07E1,32    IV24
  1112.     ;Video Toaster
  1113.     EXPBRD    2140,34    CyberVision 64/4MB
  1114.     EXPBRD    2140,50    CyberVision 64/3D
  1115.     EXPBRD    2140,67    CyberVision 64/3D
  1116.     EXPBRD    85E,1    GDA-1
  1117.     EXPBRD    86A,1    Horizon
  1118.     EXPBRD    86A,2    Blackbox 
  1119.     EXPBRD    86A,3    Voyager
  1120.     EXPBRD    877,12    Picasso II
  1121.     EXPBRD    877,13    Picasso II
  1122.     EXPBRD    877,24    Picasso IV
  1123.     EXPBRD    4754,16    RetinaZ3
  1124.     EXPBRD    4754,19,sAltais
  1125.     ;RetinaZ2? Domino? Piccolo? PiccoloSD64? RainBowIII? 1600GX?
  1126.  
  1127.     EXPBRD    201,1    A2088/A2288
  1128.     EXPBRD    201,2    A2286
  1129.     EXPBRD    201,103 A2386SX
  1130.     EXPBRD    866,1    D. Salamon Golden Gate II BridgeCard
  1131.  
  1132.     EXPBRD    2017,7    GoldenGate 80386
  1133.     EXPBRD    2017,9    GoldenGate 80486
  1134.     ;EMC 486SLC
  1135.  
  1136.     EXPBRD    200,2    3-State Megamix 2000
  1137.     EXPBRD    202,1    A2090(A)
  1138.     EXPBRD    202,4    A2090B
  1139.     EXPBRD    202,9    A2060
  1140.     EXPBRD    202,69    A2232 (prototype)
  1141.     EXPBRD    202,70    A2232
  1142.     EXPBRD    202,80    A2620 68020 turbo
  1143.     EXPBRD    202,81    A2640 68030 turbo
  1144.     EXPBRD    202,84    A4091 SCSI/SCSI-II         ???
  1145.     EXPBRD    202,112    A2065
  1146.     EXPBRD    2F4,105    A2000 68040 turbo
  1147.     EXPBRD    2F4,150  ???  68040 turbo
  1148.     EXPBRD    3EC,4    Kronos 2000            ???
  1149.     EXPBRD    3ED,1    A-Squared LIVE!
  1150.     EXPBRD    3F2,68    MicroBotics 68030 turbo???
  1151.     EXPBRD    3F2,150    MB HardFrame/2000?
  1152.     EXPBRD    3F2,158    MB HardFrame/2000?
  1153.     EXPBRD    3FF,255    Dual serial port
  1154.     EXPBRD    404,57    A2000 68030 turbo
  1155.     EXPBRD    404,87    A2000 68030 turbo
  1156.     EXPBRD    41D,1    Amerisar Ethernet
  1157.     EXPBRD    420,1    Supra 4x4
  1158.     EXPBRD    420,3    Supra 2000 DMA
  1159.     EXPBRD    420,11    Supra 2400zi internal modem
  1160.     EXPBRD    420,16    Supra 2400zi internal modem
  1161.     EXPBRD    422,17    Mag40 68040 Turbo
  1162.     EXPBRD    6E1,8    GVP Series I HD Ctrl
  1163.     EXPBRD    7E1,3    GVP Hard Card 0
  1164.     EXPBRD    7E1,8    GVP A3001 Expansion board
  1165. ;;    EXPBRD    7E1,9    GVP A3001 RAM            500/2000!!!
  1166.     EXPBRD    7E1,255    GVP GForce 68040 Turbo
  1167.     EXPBRD    7EA,105    68040 turbo???
  1168. ;;wasina500?    EXPBRD    801,6    BSC Oktagon 2008
  1169. ;;wasina500?    EXPBRD    801,8    BSC Oktagon 2008
  1170.     EXPBRD    801,16    BSC Parallel/Serial
  1171.     EXPBRD    801,32    BSC Frame Buffer
  1172.     EXPBRD    801,64    BSC ISDN Master
  1173.     EXPBRD    802,4    Kronos 2000            ???
  1174.     EXPBRD    817,1    ICD 2000 SCSI
  1175.     EXPBRD    817,4    ICD 2080 Board
  1176.     EXPBRD    81D,9    GVP A2000-Ram8/2
  1177.     EXPBRD    828,16    Applied LD2000 Modem???
  1178.     EXPBRD    82C,5    BSC Memory Master Card
  1179. ;;wasina500?    EXPBRD    82C,6    BSC Oktagon 2008        ???
  1180. ;;wasina500?    EXPBRD    82C,8    BSC Oktagon 2008
  1181.     EXPBRD    82C,18    ?
  1182.     EXPBRD    82C,64    BSC ISDN Master
  1183.     EXPBRD    87B,21    Emplant MAC emu
  1184.     EXPBRD    1028,87    Imtromix hurricane 2800
  1185.     EXPBRD    2017,7    ?
  1186.     EXPBRD    2100,1    ReadySoft Amax II+ Mac emu
  1187.     EXPBRD    2132,27    ?
  1188.     EXPBRD    4754,4    Macrosystems Framegrabber?
  1189.     EXPBRD    A9AD,17    Reis-ware Scan King
  1190.     EXPBRD    819,2    Kupke Golem SCSI II
  1191.     dc.l    0
  1192. ;;;
  1193.  
  1194.  
  1195. GetGfxBoards    movem.l    d0-d1/a0-a6,-(sp)
  1196.     lea    GfxBoardI,a4
  1197.     lea    (sNullStr,pc),a0
  1198.     move.l    a0,(a4)
  1199.     lea    GfxBoardBuffer+2,a3
  1200.     move.l    a3,(GfxBoard-GfxBoardI,a4)
  1201.     subq.l    #2,a3
  1202.  
  1203.     move.l    (4).w,a6
  1204.     cmp.w    #39,(LIB_VERSION,a6)
  1205.     blo    .nocgfx
  1206.     lea    (.cgfxname,pc),a1
  1207.     moveq    #41,d0
  1208.     call    OpenLibrary
  1209.     tst.l    d0
  1210.     beq.b    .nocgfx
  1211.     move.l    d0,a6
  1212.  
  1213.     clr.l    -(sp)
  1214.     pea    (12).w        ; Cybervision PPC
  1215.     pea    CYBRBIDTG_MONITORID
  1216.     move.l    sp,a0
  1217.     call    BestCModeIDTagList
  1218.     addq.l    #1,d0
  1219.     beq.b    .no_b1
  1220.  
  1221.     lea    (.cvppc,pc),a0
  1222.     bsr    .copy1
  1223.  
  1224. .no_b1    move.w    #14,(4+2,sp)    ; Inferno
  1225.     move.l    sp,a0
  1226.     call    BestCModeIDTagList
  1227.     addq.l    #1,d0
  1228.     beq.b    .no_b2
  1229.  
  1230.     lea    (.inferno,pc),a0
  1231.     bsr    .copy1
  1232.  
  1233. .no_b2    lea    (3*4,sp),sp
  1234.     move.l    a6,a1
  1235.     move.l    (4).w,a6
  1236.     call    CloseLibrary
  1237. .nocgfx
  1238.     lea    (GfxBoardTable,pc),a2
  1239.  
  1240. .loop    movem.l    (a2)+,d0/a0
  1241.     tst.l    d0
  1242.     beq.b    .done
  1243.     bsr    FindConfigDev
  1244.     beq.b    .loop
  1245.     bsr.b    .copy1
  1246.     bra.b    .loop
  1247.  
  1248. .done    move.b    #10,(a3)
  1249.     movem.l    (sp)+,d0-d1/a0-a6
  1250.     rts
  1251.  
  1252. .copy1    lea    (sGfxBoards,pc),a1
  1253.     move.l    a1,(a4)            Set introducer
  1254.     move.b    #'/',(a3)+
  1255.     move.b    #' ',(a3)+
  1256. .copy    move.b    (a0)+,(a3)+
  1257.     bne.b    .copy
  1258.     subq.l    #1,a3
  1259.     rts
  1260.  
  1261. .cgfxname    dc.b    'cybergraphics.library',0
  1262. .cvppc    dc.b    'CyberVision PPC',0
  1263. .inferno    dc.b    'Inferno',0
  1264.     CNOP    0,2
  1265.  
  1266.  
  1267. GetSndCards    movem.l    d0-d1/a0-a4,-(sp)
  1268.     lea    SndCardI,a4
  1269.     lea    (sNullStr,pc),a0
  1270.     move.l    a0,(a4)
  1271.     lea    SndCardBuffer+1,a3
  1272.     move.l    a3,(SndCard-SndCardI,a4)
  1273.     lea    (SndCardTable,pc),a2
  1274.     lea    (sSndCards,pc),a1
  1275.     subq.l    #1,a3
  1276.  
  1277. .loop    movem.l    (a2)+,d0/a0
  1278.     tst.l    d0
  1279.     beq.b    .done
  1280.     bsr.b    FindConfigDev
  1281.     beq.b    .loop
  1282.     move.l    a1,(a4)            Set introducer
  1283.     move.b    #'/',(a3)+
  1284. .copy    move.b    (a0)+,(a3)+
  1285.     bne.b    .copy
  1286.     subq.l    #1,a3
  1287.     bra.b    .loop
  1288.  
  1289. .done    move.b    #10,(a3)
  1290.     movem.l    (sp)+,d0-d1/a0-a4
  1291.     rts
  1292.  
  1293.  
  1294.  
  1295. ;  IN: d0=manu<<16+prod
  1296. ; OUT: d0=ConfigDev if found, else zero, ccs set!
  1297. FindConfigDev    movem.l    d1-d2/a0-a1/a6,-(sp)
  1298.     move.l    _ExpBase,a6
  1299.     sub.l    a0,a0
  1300.     moveq    #0,d1
  1301.     move.w    d0,d1
  1302.     clr.w    d0
  1303.     swap    d0
  1304.     moveq    #-1,d2
  1305.     cmp.w    d2,d0
  1306.     bne.b    .ok1
  1307.     move.l    d2,d0
  1308. .ok1    cmp.w    d2,d1
  1309.     bne.b    .ok2
  1310.     move.l    d2,d1
  1311. .ok2    call    FindConfigDev
  1312.     tst.l    d0
  1313.     movem.l    (sp)+,d1-d2/a0-a1/a6
  1314.     rts
  1315.  
  1316.  
  1317. GetOtherChips    movem.l    d0-a6,-(sp)
  1318.     lea    ChipsBuffer+2,a2
  1319.     move.l    a2,CustomChips
  1320.  
  1321.     subq.l    #2,a2
  1322.     lea    (sPaula,pc),a0
  1323.     lea    PaulaRev,a1
  1324.     move.w    (a1),d0
  1325.     bmi.b    .nopaula
  1326.     bsr.b    .print
  1327. .nopaula
  1328.     lea    (sRamsey,pc),a0
  1329.     lea    RamseyRev,a1
  1330.     tst.w    (a1)
  1331.     bmi.b    .noramsey
  1332.     bsr.b    .print
  1333. .noramsey
  1334.     lea    (sGary,pc),a0
  1335.     lea    GaryRev,a1
  1336.     tst.w    (a1)
  1337.     bmi.b    .nogary
  1338.     bsr.b    .print
  1339. .nogary
  1340.     lea    (sGayle,pc),a0
  1341.     lea    GayleRev,a1
  1342.     move.w    (a1),d0
  1343.     bmi.b    .nogayle
  1344.     bsr.b    .print
  1345. .nogayle
  1346.     tst.l    AkikoID
  1347.     beq.b    .noakiko
  1348.     lea    (sAkiko,pc),a0
  1349.     bsr.b    .print
  1350. .noakiko
  1351.     movem.l    (sp)+,d0-a6
  1352.     rts
  1353.  
  1354. .print    tst.b    (a2)+
  1355.     bne.b    .print
  1356.     move.b    #',',(-1,a2)
  1357.     move.b    #' ',(a2)+
  1358.     bra    Sprintf
  1359.  
  1360.  
  1361. ;  IN: d0=AttnFlags ('030 info available)
  1362. ; OUT: d0=ramseyrev, if z clear
  1363. GetRamsey    movem.l    d6-d7/a5-a6,-(sp)
  1364.     moveq    #0,d6
  1365.     moveq    #0,d7
  1366.     tst.l    NoHW
  1367.     bne.b    .no_chip2
  1368.     btst    #AFB_68020,d0
  1369.     beq.b    .no_chip2
  1370.  
  1371.     lea    (.supramsey,pc),a5
  1372.     move.l    (ExecBase00,pc),a6
  1373.     call    Disable
  1374.     call    Supervisor        Ramsey revision:
  1375.  
  1376.     cmp.w    #$D,d6
  1377.     blo.b    .no_chip        Minimum!
  1378.     cmp.w    #$F+5,d6        Maximum! ???
  1379.     bhi.b    .no_chip
  1380.  
  1381.     moveq    #-1,d7
  1382.  
  1383. .no_chip    call    Enable
  1384. .no_chip2    move.l    d6,d0
  1385.     tst.l    d7            <- Does set ccs
  1386.     movem.l    (sp)+,d6-d7/a5-a6    <- Doesn't set ccs!!!
  1387.     rts
  1388.  
  1389. .supramsey    move.b    $DE0043,d6
  1390. ;    move.b    #$F,d6            debug
  1391.     rte
  1392.  
  1393.  
  1394. ;  IN: d0=AttnFlags ('030 info available)
  1395. ; OUT: d0=garyrev, if z clear
  1396. GetGary    movem.l    d1-d2/d6-d7/a0/a6,-(sp)
  1397.     moveq    #0,d6
  1398.     moveq    #0,d7
  1399.     tst.l    NoHW
  1400.     bne.b    .no_chip2
  1401.     btst    #AFB_68020,d0
  1402.     beq.b    .no_chip2
  1403.  
  1404.     move.l    (ExecBase00,pc),a6
  1405.     call    Disable
  1406.  
  1407. ;    Gary revision:
  1408.     lea    $DE1002,a0
  1409.     clr.b    (a0)
  1410.     jsr    CacheClearU
  1411.     cmp.b    #$7F,(a0)
  1412.     nop
  1413.     bne.b    .no_chip
  1414.  
  1415.     clr.b    (a0)
  1416.     nop
  1417.     moveq    #7,d0
  1418. .loop    tst.b    (a0)
  1419.     nop
  1420.     bpl.b    .skip
  1421.     bset    d0,d6
  1422. .skip    dbf    d0,.loop
  1423.  
  1424.     cmp.w    #$FF,d6
  1425.     beq.b    .no_chip        All bits 1 -> No chip!
  1426.     cmp.w    #209,d6            Test for Gaylething... :)
  1427.     beq.b    .no_chip        (not really needed tho)
  1428.  
  1429.     moveq    #-1,d7
  1430.  
  1431. .no_chip    call    Enable
  1432. .no_chip2    move.l    d6,d0
  1433.     tst.l    d7            <- Does set ccs
  1434.     movem.l    (sp)+,d1-d2/d6-d7/a0/a6    <- Doesn't set ccs!!!
  1435.     rts
  1436.  
  1437.  
  1438. ;NAME   rev ADDR type chip Description
  1439. ;---------------------------------------------------------------------------
  1440. ;POTINP     016   R    P   Pot pin data read
  1441. ;
  1442. ;     Bit
  1443. ;    Number  Name              Function
  1444. ;
  1445. ;    07-01   X       Paula 8364 chip revision identification number
  1446. ;                    (presently all zeroes)
  1447.  
  1448. ; OUT: d0=paula revision or -1
  1449. GetPaula    tst.l    NoHW
  1450.     bne.b    .nohw
  1451.     IFND    potgor
  1452.     move.w    $DFF000+potinp,d0    potgor
  1453.     ELSE
  1454.     move.w    $DFF000+potgor,d0
  1455.     ENDC
  1456.  
  1457.     and.w    #%11111110,d0
  1458.     lsr.w    #1,d0
  1459.     rts
  1460.  
  1461. .nohw    moveq    #-1,d0
  1462.     rts
  1463.  
  1464.  
  1465. ; OUT: d0=Gayle revision or -1
  1466. GetGayle    movem.l    d1-a6,-(sp)
  1467.     tst.l    NoHW
  1468.     bne    .no_gayle
  1469.  
  1470.     move.l    (ExecBase00,pc),a6
  1471.  
  1472.     lea    $DFF000,a0
  1473.     lea    $DE1000,a1        Gayle port
  1474.     moveq    #0,d1
  1475.     call    Disable
  1476.     move.w    (intenar,a0),d0
  1477.     move.w    #$BFFF,(intena,a1)
  1478.     move.w    #$3FFF,d2
  1479.     cmp.w    (intenar,a0),d2
  1480.     bne.b    .skip1
  1481.     move.w    d2,(intena,a1)
  1482.     tst.w    (intenar,a0)
  1483.     bne.b    .skip1
  1484.     moveq    #1,d1
  1485. .skip1    move.w    d2,(intena,a0)
  1486.     or.w    #$8000,d0
  1487.     move.w    d0,(intena,a0)
  1488.  
  1489.     call    Enable
  1490.     tst.w    d1
  1491.     bne.b    .no_gayle
  1492.  
  1493.     moveq    #3,d2            Get revision:
  1494.     move.b    d1,(a1)
  1495. .loop    move.b    (a1),d0
  1496.     lsl.b    #1,d0
  1497.     addx.b    d1,d1
  1498.     dbra    d2,.loop
  1499.     moveq    #0,d0
  1500.     move.b    d1,d0
  1501. .exit    tst.b    d0
  1502.     bne.b    .exit2
  1503. .no_gayle    moveq    #-1,d0
  1504. .exit2    movem.l    (sp)+,d1-a6
  1505.     rts
  1506.  
  1507.  
  1508. ;  IN: d0=version<<16+revision
  1509. ; OUT: d0=ptr to null terminated kick version string (eg. '2.05',0)
  1510. GetKickStr    move.l    d1,-(sp)
  1511.     move.w    d0,d1
  1512.     swap    d0
  1513.     tst.w    d0
  1514.     beq.b    .no_rom
  1515.     sub.w    #30,d0
  1516.     cmp.w    #13,d0
  1517.     bls.b    .ok
  1518.     moveq    #14,d0
  1519. .ok    add.w    d0,d0
  1520.     lea    (_ks,pc),a0
  1521.     add.w    (a0,d0.w),a0
  1522.     cmp.w    #(37-30)*2,d0
  1523.     bne.b    .skip
  1524.     cmp.w    #175,d1            >37.175<
  1525.     bls.b    .skip
  1526.     addq.l    #(_sKS_05-_sKS7),a0
  1527. .skip    move.l    a0,d0
  1528.     move.l    (sp)+,d1
  1529.     rts
  1530. .no_rom    lea    (_sKNoROM,pc),a0
  1531.     bra.b    .skip
  1532. _wb    dc.w    _sKS0-_wb,_sKS1-_wb,_sKS2-_wb,_sKS3-_wb,_sKS4-_wb
  1533.     dc.w    _sKS5-_wb,_sKS6-_wb,_sKS7_2-_wb,_sKSWB-_wb,_sKS8-_wb
  1534.     dc.w    _sKS9-_wb,_sKSA-_wb,_sKSX-_wb
  1535. _ks    dc.w    _sKS0-_ks,_sKS1-_ks,_sKS2-_ks,_sKS3-_ks,_sKS4-_ks
  1536.     dc.w    _sKS5-_ks,_sKS6-_ks,_sKS7-_ks,_sKSH-_ks,_sKS8-_ks
  1537.     dc.w    _sKS9-_ks,_sKSH-_ks,_sKSH-_ks,_sKSA-_ks,_sKSX-_ks
  1538. _sKS0    dc.b    '1.0',0
  1539. _sKS1    dc.b    '1.1 ntsc',0
  1540. _sKS2    dc.b    '1.1 pal',0
  1541. _sKS3    dc.b    '1.2',0
  1542. _sKS4    dc.b    '1.3',0
  1543. _sKS5    dc.b    '1.4 beta',0
  1544. _sKS6    dc.b    '2.0 beta',0
  1545. _sKS8    dc.b    '3.0',0
  1546. _sKS9    dc.b    '3.1',0
  1547. _sKSA    dc.b    '3.2',0
  1548. _sKSX    dc.b    'unknown',0
  1549. _sKS7    dc.b    '2.04',0
  1550. _sKS_05    dc.b    '2.05',0
  1551. _sKSH    dc.b    'hack',0
  1552. _sKS7_2    dc.b    '2.0',0
  1553. _sKSWB    dc.b    '2.1',0
  1554. _sKNoROM
  1555. sNoSetPatch    dc.b    'version information not available',0
  1556.     CNOP    0,4
  1557.  
  1558.  
  1559. ;  IN: d0=version<<16+revision
  1560. ; OUT: d0=ptr to null terminated WB version string (eg. '2.1',0)
  1561. GetWBStr    move.l    d1,-(sp)
  1562.     move.w    d0,d1
  1563.     swap    d0
  1564.     tst.w    d0
  1565.     beq.b    .no_wb
  1566.     sub.w    #30,d0
  1567.     cmp.w    #11,d0
  1568.     bls.b    .ok
  1569.     moveq    #12,d0
  1570. .ok    add.w    d0,d0
  1571.     lea    (_wb,pc),a0
  1572.     add.w    (a0,d0.w),a0
  1573. .done    move.l    a0,d0
  1574.     move.l    (sp)+,d1
  1575.     rts
  1576. .no_wb    lea    (_sKNoROM,pc),a0
  1577.     bra.b    .done
  1578.  
  1579.  
  1580. ExtAttnFlags    movem.l    d1/d2/a0-a1/a6,-(sp)
  1581.     move.l    (4).w,a6        Use (4).w
  1582.     move.w    (AttnFlags,a6),d2
  1583.     tst.l    NoHW
  1584.     bne.b    .nohw
  1585.     cmp.w    #37,(LIB_VERSION,a6)
  1586.     bhs.b    .test060
  1587.  
  1588.     jsr    Test030_040_882
  1589.     or.w    d0,d2
  1590. ;;    bra.b    .xit
  1591.  
  1592. .test060    btst    #AFB_68040,d2        You must have 68040 flag
  1593.     beq.b    .no060            set to have 68060.
  1594.     tst.b    d2            Test #AFB_68060
  1595.     bmi.b    .is060            Is already valid!
  1596.  
  1597.     jsr    Test060            Test for 68060.
  1598. .is060
  1599. .no060
  1600. .nohw
  1601. .xit    move.w    d2,d0
  1602.     movem.l    (sp)+,d1/d2/a0-a1/a6
  1603.     rts
  1604.  
  1605.  
  1606. GetCardSlot    moveq    #0,d0
  1607.     move.w    GayleRev,d1
  1608.     cmp.w    #13,d1
  1609.     bne.b    .no_cardslot
  1610.     moveq    #-1,d0
  1611. .no_cardslot    rts
  1612.  
  1613.  
  1614.  
  1615. GetATIDE    movem.l    d1-a6,-(sp)
  1616.     lea    $00DA2000,a4        IDE port
  1617.     bsr.b    .TestIDEHW
  1618.     movem.l    (sp)+,d1-a6
  1619.     tst.l    d0
  1620.     rts
  1621.  
  1622. .TestIDEHW    move.l    d0,-(sp)
  1623.     move.w    GayleRev,d1
  1624.     cmp.w    #13,d1
  1625.     bne.b    .nohw
  1626.  
  1627.     moveq    #9,d0            Try 10 times:
  1628.     move.b    d0,(sp)
  1629. .try_again    move.b    (3,sp),($0018,a4)
  1630.     move.b    ($0010,a4),d1
  1631.     move.b    ($001C,a4),d0
  1632.     move.l    d0,a0
  1633.     and.b    #$C0,d0
  1634.     beq.b    .has2
  1635.     cmp.b    #$C0,d0
  1636.     beq.b    .nohw
  1637.     tst.b    d0
  1638.     bpl.b    .has
  1639.     move.l    a0,d0
  1640.     eor.b    d1,d0
  1641.     and.b    #$FD,d0
  1642.     bne.b    .nohw
  1643.     moveq    #2,d0
  1644.     bra.b    .exit
  1645.  
  1646. .has2    btst    #4,(3,sp)
  1647.     bne.b    .nohw
  1648.     subq.b    #1,(sp)
  1649.     bmi.b    .nohw
  1650.     bsr.b    WaitVBL
  1651.     bra.b    .try_again
  1652.  
  1653. .valid    moveq    #1,d0
  1654.     bra.b    .exit
  1655.  
  1656. .has    moveq    #$12,d0
  1657.     move.b    d0,($0010,a4)
  1658.     cmp.b    ($0010,a4),d0
  1659.     bne.b    .nohw
  1660.     moveq    #$34,d0
  1661.     move.b    d0,($0010,a4)
  1662.     cmp.b    ($0010,a4),d0
  1663.     beq.b    .valid
  1664. .nohw    moveq    #0,d0
  1665. .exit    addq.w    #4,sp
  1666.     rts
  1667.  
  1668.  
  1669. WaitVBL    moveq    #1,d0
  1670. WaitBlanks    movem.l    d2/a2/a3/a6,-(sp)
  1671.     move.l    d0,d2
  1672.     lea    (-$0022,sp),sp
  1673.     move.l    sp,a2
  1674.     move.b    #4,(8,a2)
  1675.     clr.b    (9,a2)
  1676.     clr.l    (10,a2)
  1677.     clr.b    (14,a2)
  1678.     move.b    #4,(15,a2)
  1679.     suba.l    a1,a1
  1680.     call    FindTask
  1681.     move.l    d0,($0010,a2)
  1682.     lea    ($0014,a2),a0
  1683.     move.l    a0,(8,a0)
  1684.     addq.l    #4,a0
  1685.     clr.l    (a0)
  1686.     move.l    a0,-(a0)
  1687.     lea    (-$0028,sp),sp
  1688.     move.l    sp,a3
  1689.     lea    (TimerDevName,pc),a0
  1690.     move.l    a3,a1
  1691.     moveq    #UNIT_VBLANK,d0
  1692.     moveq    #0,d1
  1693.     call    OpenDevice
  1694.     tst.l    d0
  1695.     bne.b    .exit
  1696.     move.l    a2,(IO+MN_REPLYPORT,a3)
  1697.     move.l    a3,a1
  1698.     move.w    #TR_ADDREQUEST,(IO_COMMAND,a1)
  1699.     clr.l    (IOTV_TIME+EV_HI,a1)
  1700.     move.l    d2,(IOTV_TIME+EV_LO,a1)
  1701.     call    DoIO
  1702.     move.l    a3,a1
  1703.     call    CloseDevice
  1704. .exit    lea    ($004A,sp),sp
  1705.     movem.l    (sp)+,d2/a2/a3/a6
  1706.     rts
  1707.  
  1708.  
  1709. GetDraCo    movem.l    d0-a6,-(sp)
  1710.     move.l    (4).w,a6        Use (4).w
  1711.     lea    (.DraCoName,pc),a1
  1712.     call    OpenResource
  1713.     tst.l    d0
  1714. ;;DEBUG
  1715.     beq.b    .nodraco
  1716.     st    DraCoID
  1717.     st    NoHW
  1718. .nodraco    movem.l    (sp)+,d0-a6
  1719.     rts
  1720.  
  1721. .DraCoName    dc.b    'draco.resource',0
  1722.     CNOP    0,4
  1723.  
  1724.  
  1725. GetUAE    movem.l    d0-a6,-(sp)
  1726.     move.l    (4).w,a6        Use (4).w
  1727.     call    Forbid
  1728.     move.l    (IVEXTER+IV_DATA,a6),d0
  1729.     beq.b    .nouae
  1730.     move.l    d0,a0            a0=lh
  1731.     lea    (.UAEName,pc),a1
  1732.     call    FindName
  1733.     tst.l    d0
  1734.     beq.b    .nouae
  1735.     st    UAEID
  1736. .nouae    call    Permit
  1737.     movem.l    (sp)+,d0-a6
  1738.     rts
  1739.  
  1740. .UAEName    dc.b    'UAE filesystem',0
  1741.     CNOP    0,4
  1742.  
  1743.  
  1744. GetPowerUP    movem.l    d0-a6,-(sp)
  1745.     lea    sPowerUPBuf,a0
  1746.     move.l    a0,PowerUP_ptr
  1747.     clr.b    (a0)
  1748.  
  1749.     move.l    (4).w,a6        Use (4).w
  1750.     cmp.w    #36,(LIB_VERSION,a6)
  1751.     blo    .oldkick
  1752.  
  1753.     moveq    #3*4,d0
  1754.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1
  1755.     call    AllocVec
  1756.     tst.l    d0
  1757.     beq    .nomem
  1758.     move.l    d0,a5
  1759.  
  1760.     lea    (.ppcName,pc),a1
  1761.     moveq    #44,d0
  1762.     call    OpenLibrary
  1763.     tst.l    d0
  1764.     beq    .noppc
  1765.     move.l    d0,a6
  1766.  
  1767.     move.l    #PPCINFOTAG_CPUCOUNT,(a5) Get CPU count
  1768.     move.l    a5,a0
  1769.     call    PPCGetInfo
  1770.     move.l    d0,d7
  1771.     beq    .nocpus
  1772.  
  1773.     st    PowerUPID
  1774.  
  1775.     lea    (sPowerUPFmt0,pc),a0
  1776.     move.l    d7,-(sp)
  1777.     move.l    sp,a1
  1778.     lea    sPowerUPBuf,a2
  1779.     bsr    Sprintf
  1780.     addq.l    #4,sp
  1781. .findend1    tst.b    (a2)+
  1782.     bne.b    .findend1
  1783.     subq.l    #1,a2
  1784.  
  1785.     moveq    #0,d6
  1786. .cpu_loop
  1787.     moveq    #-1,d5
  1788.     move.l    #PPCINFOTAG_CPU,(a5)    Version of the CPU
  1789.     move.l    d6,(4,a5)
  1790.     move.l    a5,a0
  1791.     call    PPCGetInfo
  1792.     moveq    #CPU_603,d1        3
  1793.     moveq    #CPU_604e,d2        9
  1794.     cmp.l    d1,d0
  1795.     blo.b    .unknown1
  1796.     cmp.l    d2,d0
  1797.     bhi.b    .unknown1
  1798.     move.l    d0,d5
  1799. .unknown1
  1800.     moveq    #10,d0
  1801.     cmp.w    #45,(LIB_VERSION,a6)
  1802.     blo.b    .noppldiv
  1803.     move.l    #PPCINFOTAG_CPUPLL,(a5)    PLL Divider of the CPU
  1804.     move.l    d6,(4,a5)
  1805.     move.l    a5,a0
  1806.     call    PPCGetInfo
  1807.     move.l    d0,d1
  1808.     and.l    #$FFFFFFF0,d1
  1809.     bne.b    .noppldiv
  1810.     moveq    #10,d0
  1811. .noppldiv    move.l    d0,-(sp)
  1812.  
  1813.     move.l    #PPCINFOTAG_CPUREV,(a5)    Get CPU revision
  1814.     move.l    d6,(4,a5)
  1815.     move.l    a5,a0
  1816.     call    PPCGetInfo
  1817.     lsl.l    #8,d0        ; ddccbbaa -> ccbbaa00
  1818.     lsr.w    #8,d0        ; ccbbaa00 -> ccbb00aa
  1819.     move.l    d0,-(sp)
  1820.  
  1821.     move.l    #PPCINFOTAG_CPUCLOCK,(a5) Clock of the CPU (Get CPU MHz)
  1822.     move.l    d6,(4,a5)
  1823.     move.l    a5,a0
  1824.     call    PPCGetInfo
  1825.     move.l    d0,-(sp)
  1826.  
  1827.     pea    (sPPCxx,pc)
  1828.     move.l    d5,d0
  1829.     bmi.b    .unknown2
  1830.     lea    (PowerPCTable,pc),a0
  1831.     move.l    sp,a1
  1832.     bsr    PutWStrPtr
  1833.  
  1834.     move.l    d5,d0
  1835.     lea    (PowerPCPLLTable,pc),a0
  1836.     add.w    d0,d0
  1837.     lea    (12,sp),a1
  1838.     add.w    (a0,d0.w),a0
  1839.     move.l    (4,sp),d0
  1840.     move.l    (a1),d1
  1841.     mulu.w    #10,d0
  1842.     add.w    d1,d1
  1843.     divu.w    0(a0,d1.w),d0
  1844.     move.l    d0,(a1)
  1845. .unknown2
  1846.     lea    (sPowerUPFmt1,pc),a0
  1847.     move.l    sp,a1
  1848.     ;a2=buffer
  1849.     bsr    Sprintf
  1850.     lea    (4*4,sp),sp
  1851. .findend2    tst.b    (a2)+
  1852.     bne.b    .findend2
  1853.     subq.l    #1,a2
  1854.  
  1855.     addq.l    #1,d6
  1856.     subq.l    #1,d7
  1857.     bne    .cpu_loop
  1858.  
  1859.     move.b    #10,(a2)+        LF
  1860.     clr.b    (a2)
  1861.  
  1862. .nocpus    move.l    a6,a1
  1863.     move.l    (4).w,a6        Use (4).w
  1864.     call    CloseLibrary
  1865. .noppc    move.l    a5,a1
  1866.     call    FreeVec
  1867. .nomem
  1868. .oldkick    movem.l    (sp)+,d0-a6
  1869.     rts
  1870.  
  1871. .ppcName    dc.b    'ppc.library',0
  1872.     CNOP    0,4
  1873.  
  1874.  
  1875. GetMisc    movem.l    d0-d7/a0-a6,-(sp)
  1876.     move.l    (ExecBase00,pc),a6
  1877.     lea    (.CardName,pc),a1
  1878.     call    OpenResource
  1879.     tst.l    d0
  1880.     sne    CardSlotID
  1881.  
  1882.     move.l    (IVPORTS,a6),a0
  1883.     lea    (.ATIDEName,pc),a1
  1884.     bsr    .findnametest
  1885.     sne    ATIDEID
  1886.  
  1887.     lea    (DeviceList,a6),a0
  1888.     lea    (.CDTVDevName,pc),a1
  1889.     bsr    .findnametest
  1890.     sne    CDTVID
  1891.  
  1892.     lea    (.A690IDName,pc),a1
  1893.     call    FindResident
  1894.     tst.l    d0
  1895.     beq.b    .no_A690
  1896.     st    A690ID
  1897.     clr.b    CDTVID
  1898. .no_A690
  1899.     lea    (sNullStr,pc),a0
  1900.     move.l    a0,C2P
  1901.     move.l    _GfxBase,a0
  1902.     cmp.w    #40,(LIB_VERSION,a0)
  1903.     blo.b    .no40
  1904.     tst.l    (gb_ChunkyToPlanarPtr,a0)
  1905.     beq.b    .noC2P
  1906.     lea    (sHWC2P,pc),a0
  1907.     move.l    a0,C2P
  1908.     st    C2PID
  1909.  
  1910.     lea    (.NonvolName,pc),a1
  1911.     moveq    #40,d0
  1912.     call    OpenLibrary
  1913.     tst.l    d0
  1914.     beq.b    .nononvol
  1915.     move.l    d0,a6
  1916.  
  1917.     moveq    #1,d1            Kill requesters
  1918.     call    GetNVInfo
  1919.     tst.l    d0
  1920.     beq.b    .caseoffailure
  1921.     move.l    d0,a0
  1922.  
  1923.     move.l    (a0),d0            nvi_MaxStorage
  1924.     beq.b    .noNV
  1925.     cmp.l    #128*1024,d0        Estimated...
  1926.     slo    CD32NVRAMID        It's not an emulator!
  1927. .noNV    call    FreeNVData
  1928.  
  1929. .caseoffailure    move.l    a6,a1
  1930.     move.l    (ExecBase00,pc),a6
  1931.     call    CloseLibrary
  1932. .nononvol
  1933. .noC2P
  1934. .no40
  1935.     move.l    _DosBase,a1        Find UNI/01 partitions:
  1936.     move.l    (dl_Root,a1),a2
  1937.     moveq    #DLT_VOLUME,d1
  1938.  
  1939.     move.l    (ExecBase00,pc),a6
  1940.     call    Forbid
  1941.  
  1942.     move.l    (rn_Info,a2),a0
  1943.     add.l    a0,a0
  1944.     add.l    a0,a0
  1945.     move.l    (di_DevInfo,a0),d0
  1946. .nextdev    beq.b    .devs_scanned
  1947.     lsl.l    #2,d0
  1948.     move.l    d0,a0
  1949.     cmp.l    (dl_Type,a0),d1        (d1=DLT_VOLUME)
  1950.     bne.b    .gnd
  1951.     cmp.l    #ID_UNIX_DISK,(dl_DiskType,a0)
  1952.     seq    UNIXID
  1953.     beq.b    .devs_scanned
  1954. .gnd    move.l    (a0),d0            dl_Next
  1955.     bra.b    .nextdev
  1956.  
  1957. .devs_scanned    call    Permit
  1958.  
  1959.     move.l    #$202<<16+80,d0        Try to find 'A2620 68020 Accelerator / RAM Board'
  1960.     bsr    FindConfigDev
  1961.     sne    A2500ID
  1962.     bne.b    .is2500
  1963.     move.l    #$202<<16+81,d0        Try to find 'A2630 68030 Accelerator / RAM Board'
  1964.     bsr    FindConfigDev
  1965.     sne    A2500ID
  1966. .is2500
  1967.  
  1968.     move.l    #$202<<16+84,d0        Try to find 'CBM A4091 SCSI/SCSI-II HD Controller'
  1969.     bsr    FindConfigDev
  1970.     sne    A4091ID
  1971.  
  1972.     move.l    #$2140<<16!$FFFF,d0    Try to find any 'Phase 5 Digital Products'
  1973.     bsr    FindConfigDev
  1974.     sne    Phase5ID
  1975.  
  1976.  
  1977.  
  1978.     bsr    GetPowerUP
  1979.     DBG    'gpup'
  1980.  
  1981.     bsr    GetUAE
  1982.     DBG    'guae'
  1983.  
  1984.     bsr    GetClock
  1985.     move.l    d0,HWClockID
  1986.     DBG    'gclk'
  1987.  
  1988.     movem.l    (sp)+,d0-d7/a0-a6
  1989.     rts
  1990.  
  1991. .findnametest    call    Disable
  1992.     call    FindName
  1993.     call    Enable
  1994.     tst.l    d0
  1995.     rts
  1996.  
  1997. .CardName    dc.b    'card.resource',0
  1998. .CDTVDevName    dc.b    'cdtv.device',0
  1999. .A690IDName    dc.b    'A690ID',0
  2000. .ATIDEName    dc.b    'AT-IDE',0
  2001. .NonvolName    dc.b    'nonvolatile.library',0
  2002.     CNOP    0,4
  2003.  
  2004.  
  2005. ;  IN: -
  2006. ; OUT: d0=zero if no clock, nonzero if clock found
  2007. GetClock    movem.l    d1-a6,-(sp)
  2008.     moveq    #0,d7
  2009.     move.l    (ExecBase00,pc),a6
  2010.     call    Forbid
  2011.     lea    (.battclockres,pc),a1
  2012.     call    OpenResource
  2013.     tst.l    d0
  2014.     beq.b    .nores
  2015.     move.l    d0,a6
  2016.     jsr    (-12,a6)
  2017.     move.l    (ExecBase00,pc),a6
  2018.     tst.l    d0
  2019.     beq.b    .exit
  2020.     bra.b    .found
  2021.  
  2022. .nores    lea    $DC0001,a0
  2023.     moveq    #0,d2
  2024.     moveq    #0,d1
  2025. .loop    moveq    #15,d2
  2026.     and.b    (a0),d2
  2027.     cmp.b    #9,d2
  2028.     beq.b    .loop
  2029.     addq.b    #1,d2
  2030.     bsr.b    .wait
  2031.     moveq    #$F,d1
  2032.     and.b    (a0),d1
  2033.     sub.b    d2,d1
  2034.     beq.b    .found
  2035.     cmp.b    #1,d1
  2036.     bne.b    .exit
  2037. .found    moveq    #1,d7
  2038. .exit    call    Permit
  2039.     move.l    d7,d0
  2040.     movem.l    (sp)+,d1-a6
  2041.     rts
  2042.  
  2043. .wait    bsr.b    .wait2
  2044.     move.l    d0,d1
  2045. .wloop    bsr.b    .wait2
  2046.     sub.l    d1,d0
  2047.     cmp.l    #60,d0
  2048.     bne.b    .wloop
  2049.     rts
  2050. .wait2    moveq    #0,d0
  2051.     move.b    $BFEA01,d0
  2052.     lsl.w    #8,d0
  2053.     move.b    $BFE901,d0
  2054.     lsl.l    #8,d0
  2055.     move.b    $BFE801,d0
  2056.     rts
  2057.  
  2058. .battclockres    dc.b    'battclock.resource',0
  2059.     CNOP    0,2
  2060.  
  2061.  
  2062. GetProcInfo    movem.l    d0-a6,-(sp)
  2063.     lea    (sNullStr,pc),a2
  2064.     tst.b    _AttnFlags+1
  2065.     bpl.b    .no060
  2066.  
  2067.     lea    (.getpcr,pc),a5
  2068.     call    Supervisor
  2069.     lsr.w    #8,d0
  2070.     swap    d0            d0.l=rev<<16!id
  2071.     move.l    d0,-(sp)
  2072.  
  2073.     lea    (sProcInfo060Fmt,pc),a0
  2074.     move.l    sp,a1
  2075.     lea    sPI060Buffer,a2
  2076.     bsr    Sprintf
  2077.     move.l    (sp)+,d0
  2078.  
  2079.     cmp.w    #%0000010000110000,d0    fix CPUID according to CPU internal info
  2080.     bne.b    .not68060
  2081.  
  2082.     move.l    #MC68060,CPUID
  2083.  
  2084. .not68060    cmp.w    #%0000010000110001,d0
  2085.     bne.b    .not68xx060
  2086.  
  2087.     move.l    #MC68EC060,CPUID    no FPU, no MMU -> EC060
  2088.  
  2089.     tst.l    _MMUID
  2090.     beq.b    .nommu
  2091.     move.l    #MC68LC060,CPUID    no FPU, MMU -> LC060
  2092. .nommu
  2093. .not68xx060
  2094.  
  2095. .no060    move.l    a2,procinfo_ptr
  2096.     movem.l    (sp)+,d0-a6
  2097.     rts
  2098.  
  2099. .getpcr    or.w    #$700,sr
  2100.     dc.w    $4E7A,$0808    movec    pcr,d0
  2101.     nop
  2102.     rte
  2103.  
  2104.  
  2105.  
  2106. GetCPU    jsr    GetAddressBits
  2107.     move.l    d0,AddrBits
  2108.  
  2109.     DBG    'gabi'
  2110.  
  2111.     move.w    _AttnFlags,d0
  2112.     bsr    GetMinCPUnum
  2113.     move.l    d0,d7
  2114.  
  2115.     cmp.b    #MIN020,d7
  2116.     bne.b    .not_020
  2117.     cmp.w    #32,AddrBits+2
  2118.     bne.b    .is_EC020
  2119.     st    _EC
  2120.     addq.l    #MC68020-MC68EC020,d7
  2121. .is_EC020    bra.b    .proc_ok
  2122. .not_020
  2123.     cmp.b    #MIN030,d7
  2124.     bne.b    .not_030
  2125.     tst.l    _MMUID
  2126.     beq.b    .is_EC030
  2127.     addq.l    #MC68030-MC68EC030,d7
  2128. .is_EC030    bra.b    .proc_ok
  2129. .not_030
  2130.     cmp.b    #MIN040,d7
  2131.     beq.b    .test_040
  2132.     cmp.b    #MIN060,d7
  2133.     bne.b    .not_040
  2134.  
  2135. .test_040    btst    #AFB_FPU40,_AttnFlags+1
  2136.     bne.b    .is_full
  2137.     tst.l    _MMUID
  2138.     beq.b    .proc_ok
  2139.     addq.l    #1,d7
  2140.     bra.b    .proc_ok
  2141. .is_full    addq.l    #2,d7
  2142. ;;    bra.b    .proc_ok
  2143. .not_040
  2144. .proc_ok
  2145.     move.l    d7,CPUID
  2146.  
  2147.     IFGT    0
  2148.     move.l    (4).w,a6
  2149.     move.w    _AttnFlags,d0
  2150.     btst    #AFB_68030,d0        If 68000, 68010 or 68020 use old one.
  2151.     beq.b    .getmhz_old
  2152.     cmp.w    #37,(LIB_VERSION,a6)    If V37+ and 68030+ use new one.
  2153.     blo.b    .getmhz_old
  2154.     bsr    GetMHz
  2155.     bra.b    .getmhz_new
  2156.     ENDC
  2157.  
  2158. .getmhz_old    bsr    GetMHz_old
  2159. .getmhz_new    move.l    d0,_100kHz
  2160.  
  2161.  
  2162.     lea    (s68000,pc),a0
  2163.     moveq    #7,d1
  2164.     move.l    CPUCompareTime,d0
  2165.     divu.w    #180356/4,d0        68000 @ 7 MHz
  2166.     addq.w    #4/2,d0            Add 0.5 for correct rounding!
  2167.     lsr.w    #2,d0            /4
  2168.     cmp.w    #16,d0
  2169.     bls.b    .cmpbaseok
  2170.  
  2171.     lea    (s68030,pc),a0
  2172.     moveq    #25,d1
  2173.     move.l    CPUCompareTime,d0
  2174.     divu.w    #1442744/32,d0        68030 @ 25 MHz
  2175.     add.w    #32/2,d0        Add 0.5 for correct rounding!
  2176.     lsr.w    #5,d0            /32
  2177.  
  2178. .cmpbaseok    move.w    d0,Multiplier
  2179.     move.l    a0,CmpCPU_ptr
  2180.     move.w    d1,CmpCPUMHz
  2181.  
  2182.     rts
  2183.  
  2184.  
  2185. ;  IN: D0.w=attnflags
  2186. ; OUT: D0.l=procnum
  2187. GetMinCPUnum    move.l    d1,-(sp)
  2188.     move.l    d0,d1
  2189.     moveq    #0,d0
  2190.     btst    #AFB_68010,d1
  2191.     beq.b    .exit
  2192.     moveq    #MC68010,d0
  2193.     btst    #AFB_68020,d1
  2194.     beq.b    .exit
  2195.     moveq    #MIN020,d0
  2196.     btst    #AFB_68030,d1
  2197.     beq.b    .exit
  2198.     moveq    #MIN030,d0
  2199.     btst    #AFB_68040,d1
  2200.     beq.b    .exit
  2201.     moveq    #MIN040,d0
  2202.     tst.b    d1            Test #AFB_68060
  2203.     bpl.b    .exit
  2204.     moveq    #MIN060,d0
  2205.  
  2206. .exit    move.l    (sp)+,d1
  2207.     rts
  2208.  
  2209.  
  2210.     ; New MHz calculator
  2211.  
  2212.     IFND    _LVOSubTime
  2213. _LVOSubTime    EQU    -$30
  2214.     ENDC
  2215.  
  2216. ; OUT: D0=100kHz
  2217. GetMHz    movem.l    d1-d7/a0-a6,-(sp)
  2218.     moveq    #0,d7    
  2219.     move.l    (4).w,a6
  2220.  
  2221.     lea    (.utilname,pc),a1
  2222.     moveq    #37,d0
  2223.     call    OpenLibrary
  2224.     move.l    d0,_gcUtilBase
  2225.     beq.b    .noutil
  2226.  
  2227.     lea    (DeviceList,a6),a0
  2228.     lea    (.timername,pc),a1
  2229.     call    Forbid
  2230.     call    FindName
  2231.     call    Permit
  2232.     move.l    d0,_gcTimerBase
  2233.     beq.b    .notimer
  2234.  
  2235.     move.w    _AttnFlags,d0
  2236.     bsr    .get
  2237.     move.l    d0,d7
  2238.  
  2239. .notimer    move.l    _gcUtilBase,a1
  2240.     move.l    (4).w,a6
  2241.     call    CloseLibrary
  2242.  
  2243. .noutil    move.l    d7,d0
  2244.     movem.l    (sp)+,d1-d7/a0-a6
  2245.     rts
  2246.  
  2247. .gfxname    dc.b    'graphics.library',0
  2248. .utilname    dc.b    'utility.library',0
  2249. .timername    dc.b    'timer.device',0
  2250.     CNOP    0,2
  2251.  
  2252.  
  2253. ;  IN: D0.w=attnflags
  2254. ; OUT: D0=100kHz<<16+procnum
  2255. .get    movem.l    d1-d3/d6-d7,-(sp)
  2256.     move.l    d0,d6
  2257.     moveq    #0,d7
  2258.  
  2259.     bsr    .DoTimer
  2260.     move.l    d0,WAIndex
  2261.     tst.l    d0
  2262.     beq    .gcerror
  2263.     tst.l    _gcETicker
  2264.     beq    .gcerror
  2265.     move.l    CPUID,d1
  2266.     add.l    d1,d1
  2267.     add.l    d1,d1
  2268.     move.l    .gcSpeedTable(pc,d1.l),d2
  2269.  
  2270.     move.l    _gcUtilBase,a6
  2271.     move.l    #100,d1
  2272.     call    UMult32
  2273.     move.l    _gcETicker,d1
  2274.     call    UDivMod32
  2275.     move.l    d0,d1
  2276.     beq    .gcerror
  2277.     move.l    d2,d0
  2278.     call    UDivMod32
  2279.  
  2280.     move.l    d0,d7
  2281. .gcerror
  2282.     move.l    d7,d0
  2283.     movem.l    (sp)+,d1-d3/d6-d7
  2284.     rts
  2285.  
  2286. .gcSpeedTable
  2287.     dc.l    ($1016BF*100/70938)*5000+5000    000  7.09379 MHz
  2288.     dc.l    ($1016BF*100/70938)*5000+5000    010  7.09379 MHz
  2289.     dc.l    ($ADDBB*100/70938)*4000+4000    020 14.18758 MHz
  2290.     dc.l    ($ADDBB*100/70938)*4000+4000
  2291.     dc.l    ($ADDBB*100/70938)*4000+4000    030 40.00000 MHz
  2292.     dc.l    ($ADDBB*100/70938)*4000+4000
  2293.     dc.l    ($341BF*100/70938)*4000+4000    040 40.00000 MHz
  2294.     dc.l    ($341BF*100/70938)*4000+4000
  2295.     dc.l    ($341BF*100/70938)*4000+4000
  2296.     dc.l    ($116BF*100/70938)*5000+5000    060 50.00000 MHz
  2297.     dc.l    ($116BF*100/70938)*5000+5000
  2298.     dc.l    ($116BF*100/70938)*5000+5000
  2299.  
  2300.  
  2301. ;  IN: d6.w=attnflags
  2302. ; OUT: D0.l=compare time
  2303. .DoTimer    movem.l    d1-d7/a0-a6,-(sp)
  2304.     move.l    (4).w,a6
  2305.  
  2306.     move.l    _ThisTask,a1
  2307.     moveq    #127,d0
  2308.     call    SetTaskPri
  2309.     move.l    d0,-(sp)
  2310.  
  2311.     cmp.w    #4,BandWidth
  2312.     beq.b    .is_aga4x
  2313.     move.l    _GfxBase,a6
  2314.     move.l    (gb_ActiView,a6),-(sp)    save view
  2315.     sub.l    a1,a1
  2316.     call    LoadView
  2317.     call    WaitTOF
  2318.     call    WaitTOF
  2319. .is_aga4x
  2320.     move.l    _GfxBase,a6
  2321.     call    WaitBlit        Wait possible blit to finish.
  2322.  
  2323.     bsr    .timing2
  2324.     move.l    d0,d7
  2325.  
  2326.     cmp.w    #4,BandWidth        Restore view, if needed
  2327.     beq.b    .is_aga4x2
  2328.     move.l    _GfxBase,a6
  2329.     move.l    (sp)+,a1
  2330.     call    LoadView
  2331.     call    WaitTOF
  2332.     call    WaitTOF
  2333. .is_aga4x2
  2334.     move.l    (4).w,a6
  2335.     move.l    _ThisTask,a1
  2336.     move.l    (sp)+,d0
  2337.     call    SetTaskPri
  2338.  
  2339.     move.l    d7,d0
  2340.     movem.l    (sp)+,d1-d7/a0-a6
  2341.     rts
  2342.  
  2343.  
  2344. ;  IN: d6.w=attnflags
  2345. .timing2    move.l    (4).w,a6
  2346.     moveq    #MEMF_CHIP,d1            chipmem for 000 and 010
  2347.     btst    #AFB_68020,d6
  2348.     beq.b    .tgoalloc
  2349.     move.l    #MEMF_ANY!MEMF_PUBLIC,d1    any mem for 020
  2350.     btst    #AFB_68030,d6
  2351.     beq.b    .tgoalloc
  2352.     move.l    #MEMF_FAST!MEMF_PUBLIC,d1    fastmem for 030, 040 and 060
  2353. .tgoalloc
  2354.     move.l    #CODE020SIZE,d0
  2355.     call    AllocVec
  2356.     tst.l    d0
  2357.     beq    .nomem
  2358.     move.l    d0,a5
  2359.     lea    (.code020,pc),a0
  2360.     move.l    a5,a1
  2361.     move.l    #CODE020SIZE,d0
  2362.     call    CopyMemQuick
  2363.  
  2364.     call    Forbid
  2365.  
  2366.     move.l    #CACRF_EnableI,d0    Disable all but inst cache for test
  2367.     move.l    #~CACRF_WriteAllocate,d1
  2368.     call    CacheControl
  2369.     move.l    d0,-(sp)        Save prev cache state
  2370.  
  2371.     bsr    turnon060caches
  2372.  
  2373.     jsr    (a5)
  2374.  
  2375.     bsr    restore060caches
  2376.  
  2377.     move.l    (4).w,a6        Restore cache state
  2378.     move.l    (sp)+,d0
  2379.     move.l    #~CACRF_WriteAllocate,d1
  2380.     call    CacheControl
  2381.  
  2382.     call    Permit
  2383.  
  2384.     move.l    a5,a1
  2385.     call    FreeVec
  2386.  
  2387.     move.l    _gcTimerBase,a6
  2388.     move.l    a3,a0
  2389.     move.l    a2,a1
  2390.     call    SubTime
  2391.     move.l    (EV_LO,a3),d0
  2392.     rts
  2393.  
  2394. .nomem    moveq    #0,d0
  2395.     rts
  2396.  
  2397.     CNOP    0,8
  2398. .code020    tst.l    NoHW            ** NO PC REL!
  2399.     bne.b    .skiphw1
  2400.     lea    $DFF000,a4
  2401.     move.w    (intenar,a4),d0
  2402.     move.w    #$7FFF,(intena,a4)
  2403.     swap    d0
  2404.     move.w    (dmaconr,a4),d0
  2405.     move.w    #$000F,(dmacon,a4)    Disable audio
  2406.     move.w    #$C008,(intena,a4)    Enable INT2 & CIAA int
  2407.     or.l    #$80008000,d0
  2408.     move.l    d0,-(sp)
  2409. .skiphw1
  2410.     move.l    _gcTimerBase,a6        ** NO PC REL!
  2411.     lea    _gcStartE,a2        ** NO PC REL!
  2412.     lea    _gcEndE,a3        ** NO PC REL!
  2413.     move.l    #5000000,d4
  2414.  
  2415.     move.l    a2,a0
  2416.     call    ReadEClock
  2417.     bra.b    .loop020
  2418.     CNOP    0,8
  2419. .loop020    subq.l    #1,d4
  2420.     bne.b    .loop020
  2421.  
  2422.     move.l    a3,a0
  2423.     call    ReadEClock
  2424.     add.w    #50,d0
  2425.     divu.w    #100,d0
  2426.     and.l    #$0FFFF,d0
  2427.     move.l    d0,_gcETicker        ** NO PC REL!
  2428.  
  2429.     tst.l    NoHW            ** NO PC REL!
  2430.     bne.b    .skiphw2
  2431.     move.l    (sp)+,d0
  2432.     move.w    #$7FFF,(intena,a4)
  2433.     move.w    d0,(dmacon,a4)
  2434.     swap    d0
  2435.     move.w    d0,(intena,a4)
  2436. .skiphw2    rts
  2437. CODE020SIZE    EQU    (*-.code020+7)&-8
  2438.  
  2439.  
  2440.  
  2441. turnon060caches
  2442.     tst.b    _AttnFlags+1        Test #AFB_68060
  2443.     bpl.b    .exit
  2444.     movem.l    d0-d1/a5-a6,-(sp)
  2445.     move.l    (4).w,a6
  2446.     lea    (.turnon,pc),a5
  2447.     call    Supervisor
  2448.     movem.l    (sp)+,d0-d1/a5-a6
  2449. .exit    rts    
  2450.  
  2451. .turnon    or.w    #$700,sr
  2452.     dc.w    $4E7A,$0002    movec    cacr,d0
  2453.     dc.w    $4E7A,$1808    movec    pcr,d1
  2454.     and.l    #$F8E0E000,d0    mask all 060 used bits
  2455.     and.l    #$00000083,d1    ditto
  2456.     move.l    d0,_gcoldcacr    store old values
  2457.     move.l    d1,_gcoldpcr    for restore
  2458.     and.l    #~$D8006000,d0    EDC off, NAD off, DPI off, FOC off, NAI off, FIC off
  2459.     or.l    #$20808000,d0    enable store buffer, enable instruction cache, enable branch cache
  2460.     or.w    #$1,d1        enable superscalar dispatch
  2461. _restorego    or.w    #$700,sr
  2462.     dc.w    $4E7B,$0002    movec    d0,cacr
  2463.     dc.w    $4E7B,$1808    movec    d1,pcr
  2464.     dc.w    $F518,$F4F8,$F4D8
  2465.     nop
  2466.     rte
  2467.  
  2468.  
  2469. restore060caches
  2470.     tst.b    _AttnFlags+1        Test #AFB_68060
  2471.     bpl.b    .exit
  2472.     movem.l    d0-d1/a5-a6,-(sp)
  2473.     move.l    (4).w,a6
  2474.     lea    (_restorego,pc),a5
  2475.     move.l    _gcoldcacr,d0
  2476.     move.l    _gcoldpcr,d1
  2477.     call    Supervisor
  2478.     movem.l    (sp)+,d0-d1/a5-a6
  2479. .exit    rts    
  2480.  
  2481.     CNOP    0,4
  2482. _gcUtilBase    dc.l    0
  2483. _gcTimerBase    dc.l    0
  2484. _gcStartE    dc.l    0,0
  2485. _gcEndE    dc.l    0,0
  2486. _gcETicker    dc.l    0
  2487. _gcoldcacr    dc.l    0
  2488. _gcoldpcr    dc.l    0
  2489.  
  2490.  
  2491.  
  2492. ; OUT: D0.l=100kHz
  2493. GetMHz_old    movem.l    d1-d3/d7/a5-a6,-(sp)
  2494.     move.l    (4).w,a6
  2495.     moveq    #0,d7
  2496.  
  2497.     tst.l    DraCoID
  2498.     bne    .draco
  2499.  
  2500.     lea    (sNoHW,pc),a0
  2501.     tst.l    NoHW
  2502.     bne    .printerr
  2503.  
  2504.     moveq    #MEMF_CHIP,d1            chipmem for 000, 010, 020 and 030
  2505.     btst    #AFB_68040,_AttnFlags+1
  2506.     beq.b    .tgoalloc
  2507.     move.l    #MEMF_FAST!MEMF_PUBLIC,d1    fastmem for 040 and 060
  2508. .tgoalloc
  2509.     moveq    #CPUTIMER_SIZEOF,d0
  2510.     call    AllocMem
  2511.     tst.l    d0
  2512.     beq    .exit
  2513.     move.l    d0,a5
  2514.     move.l    d0,a1
  2515.     lea    CPU_chiptiming,a0
  2516.     moveq    #CPUTIMER_SIZEOF,d0
  2517.     call    CopyMem    
  2518.  
  2519.     bsr    InitTimer
  2520.     lea    (sNotimer,pc),a0
  2521.     move.l    d0,TimerBit
  2522.     bmi.b    .printerr
  2523.     moveq    #1,d1
  2524.     lsl.l    d0,d1
  2525.     move.l    d1,TimerMask
  2526.  
  2527.     DBG    'itim'
  2528.  
  2529.     move.l    a5,a0
  2530.     bsr    DoTimer
  2531.     move.l    d0,CPUCompareTime
  2532.     move.l    d0,WAIndex
  2533.     move.l    TimerBit,d0
  2534.     bsr    RemTimer
  2535.  
  2536.     DBG    'dtim'
  2537.  
  2538.     move.l    CPUID,d1
  2539.     add.l    d1,d1
  2540.     move.w    .SpeedCompareTable(pc,d1.l),d2
  2541.     move.w    d2,d3
  2542.     lsr.w    #1,d3            \
  2543.     ext.l    d3             > add 0.5 for rounding
  2544.     add.l    CPUCompareTime,d3    /
  2545.     divu.w    d2,d3
  2546.     move.w    d3,d7
  2547.  
  2548.     move.l    (4).w,a6
  2549.     move.l    a5,a1
  2550.     moveq    #CPUTIMER_SIZEOF,d0
  2551.     call    FreeMem
  2552.  
  2553. .exit    move.l    d7,d0
  2554.     movem.l    (sp)+,d1-d3/d7/a5-a6
  2555.     rts
  2556.  
  2557. .draco    move.l    #500,d7            50.0 MHz
  2558.     bra.b    .exit
  2559.  
  2560. .printerr    pea    (sCPU,pc)
  2561.     move.l    a0,-(sp)
  2562.     lea    (sMhzxxxErr,pc),a0
  2563.     move.l    sp,a1
  2564.     bsr    Printf
  2565.     addq.l    #8,sp
  2566.     bra.b    .exit
  2567.  
  2568. .SpeedCompareTable
  2569.     dc.w    2542    000  7.09379 MHz  180355.75 !
  2570.     dc.w    2542    010  7.09379 MHz  180355.75 !
  2571.     dc.w    5771    020 14.18758 MHz  818761.57 !
  2572.     dc.w    5771
  2573.     dc.w    5771    030 50.00000 MHz 2885487.07 ! 25.00000 MHz 1443364!
  2574.     dc.w    5771
  2575.     dc.w    15396    040 40.00000 MHz 6158519.00 !
  2576.     dc.w    15396
  2577.     dc.w    15396
  2578.     dc.w    46187    060 50.00000 MHz 23093284.5 !
  2579.     dc.w    46187
  2580.     dc.w    46187
  2581.  
  2582.  
  2583. ;  IN: D0.w=attnflags
  2584. ; OUT: D0.l=FPUID, 0=n/a, 1=68881, 2=68882, 3=68040, 4=68060
  2585. GetMinFPUnum    move.l    d1,-(sp)
  2586.     move.w    d0,d1
  2587.     moveq    #NOMATH,d0
  2588.     btst    #AFB_68040,d1
  2589.     beq.b    .no_040FPU
  2590.     btst    #AFB_FPU40,d1
  2591.     beq.b    .exit
  2592.     moveq    #MC68040i,d0
  2593.     tst.b    d1            Test #AFB_68060
  2594.     bpl.b    .exit
  2595.     moveq    #MC68060i,d0
  2596.     bra.b    .exit
  2597.  
  2598. .no_040FPU    moveq    #0,d0
  2599.     btst    #AFB_68882,d1
  2600.     beq.b    .no882
  2601.     moveq    #MC68882,d0
  2602.     bra.b    .exit
  2603. .no882    btst    #AFB_68881,d1
  2604.     beq.b    .no881
  2605.     moveq    #MC68881,d0
  2606.     ;bra.b    .exit
  2607. .no881
  2608. .exit    move.l    (sp)+,d1
  2609.     rts
  2610.  
  2611. ;  IN: D0.w=attnflags
  2612. ; OUT: D0.l=100kHz<<16+FPUID, 0=n/a, 1=68881, 2=68882, 3=68040, 4=68060
  2613. GetFPU    movem.l    d1-a6,-(sp)
  2614.     bsr    GetMinFPUnum
  2615.     move.l    d0,d7
  2616.     beq.b    .exit
  2617.  
  2618.     tst.l    DraCoID
  2619.     bne.b    .draco
  2620.  
  2621.     lea    (sNoHW,pc),a0
  2622.     tst.l    NoHW
  2623.     bne.b    .printerr
  2624.  
  2625.     bsr    InitTimer
  2626.     lea    (sNotimer,pc),a0
  2627.     move.l    d0,TimerBit
  2628.     bmi.b    .printerr
  2629.     moveq    #1,d1
  2630.     lsl.l    d0,d1
  2631.     move.l    d1,TimerMask
  2632.  
  2633.     DBG    'fiti'
  2634.  
  2635.     lea    FPU_chiptiming,a0
  2636. ;;    bsr    DoTimer
  2637.     move.l    d0,FPUCompareTime
  2638.     move.l    TimerBit,d0
  2639.     bsr    RemTimer
  2640.  
  2641.     DBG    'fdti'
  2642.  
  2643.     ; on 881 8 fadd/fsub take 8*51 cycles
  2644.     ; on 882 8 fadd fsub (8*56)-(8*17) cycles
  2645.  
  2646.     move.l    d7,d1
  2647.     add.l    d1,d1
  2648.     move.w    .SpeedCompareTable-2(pc,d1.l),d2
  2649.     ;move.w    d2,d3
  2650.     ;lsr.w    #1,d3            \
  2651.     ;ext.l    d3             > add 0.5 for rounding
  2652.     ;add.l    FPUCompareTime,d3    /
  2653.     move.l    FPUCompareTime,d3
  2654.     divu.w    d2,d3
  2655.     swap    d7
  2656.     move.w    d3,d7
  2657.     swap    d7
  2658.  
  2659. .exit    move.l    d7,d0
  2660.     movem.l    (sp)+,d1-a6
  2661.     rts
  2662.  
  2663.     ; Should use CPU MHz as default instead :)
  2664. .draco    or.l    #500<<16,d7        50.0 MHz
  2665.     bra.b    .exit
  2666.  
  2667. .printerr    pea    (sFPU,pc)
  2668.     move.l    a0,-(sp)
  2669.     lea    (sMhzxxxErr,pc),a0
  2670.     move.l    sp,a1
  2671.     bsr    Printf
  2672.     addq.l    #8,sp
  2673.     bra.b    .exit
  2674.  
  2675. .SpeedCompareTable
  2676.     dc.w    1126680/16/500    881
  2677.     dc.w    173203/500    882 50.00000 MHz  112669
  2678.     dc.w    225*8        040 40.00000 MHz  
  2679.     dc.w    225*16        060 50.00000 MHz  
  2680.  
  2681.  
  2682.  
  2683.  
  2684. ;  IN: GfxBase in _GfxBase
  2685. ; OUT: d0=0=OCS, 1=ECS, 2=AGA, 3=CyberGfx, 4=Picasso96, 5=Probench, 6=EGS, 7=Retina,
  2686. ;         8=Graffiti, 9=TIGA, 10=Altais
  2687. ;      d1=bandwidth (1, 2 or 4)
  2688. GetGfxLibEmul    move.l    d2,-(sp)
  2689.  
  2690.     moveq    #0,d0
  2691.     move.w    AnimChipID+2,d1
  2692.     subq.w    #5,d1
  2693.     bmi.b    .oldtestdone
  2694.     moveq    #1,d0
  2695. ;;    subq.w    #8-4,d1
  2696. ;;    bmi.b    .oldtestdone
  2697. .oldtestdone
  2698.     moveq    #1,d1
  2699.     move.l    _GfxBase,a0
  2700.     cmp.w    #37,(LIB_VERSION,a0)
  2701.     blo.b    .xit
  2702.     move.b    (gb_ChipRevBits0,a0),d2
  2703.     move.b    d2,d1
  2704.     moveq    #0,d0             OCS %10001
  2705.     and.b    #GFXF_HR_DENISE|GFXF_AA_LISA|GFXF_AA_ALICE,d1 %0xxx0
  2706.     beq.b    .done
  2707.     moveq    #2,d0              AGA %11111
  2708.     cmp.b    #GFXF_HR_DENISE|GFXF_AA_LISA|GFXF_AA_ALICE,d1
  2709.     beq.b    .done
  2710.     moveq    #1,d0            ECS %10011
  2711. ;;    cmp.b    #GFXF_HR_DENISE,d1
  2712. ;;    beq.b    .done
  2713. .done
  2714.     moveq    #0,d1
  2715.     move.b    (gb_MemType,a0),d1
  2716.     and.b    #3,d1
  2717.     addq.l    #1,d1
  2718.     cmp.b    #3,d1
  2719.     bne.b    .xit
  2720.     subq.l    #1,d1
  2721. .xit
  2722.     bsr.b    .getgfxg
  2723.  
  2724.     move.l    (sp)+,d2
  2725.     tst.l    d0
  2726.     rts
  2727.  
  2728.  
  2729. ; OUT: d0=0=OCS, 1=ECS, 2=AGA, 3=CyberGfx, 4=Picasso96, 5=Probench, 6=EGS, 7=Retina,
  2730. ;         8=Graffiti, 9=TIGA, 10=Altais
  2731.  
  2732. ; DosBase in _DosBase, ThisTask in _ThisTask
  2733.  
  2734. .getgfxg    tst.b    DraCoID
  2735.     beq.b    .not_altais
  2736.     moveq    #10,d0
  2737.     rts
  2738. .not_altais    movem.l    d0-a6,-(sp)
  2739.     move.l    (ExecBase00,pc),a6
  2740.  
  2741.     lea    (.picassortg,pc),a1
  2742.     lea    (LibList,a6),a0
  2743.     call    FindName
  2744.     tst.l    d0
  2745.     beq.b    .notp96
  2746.     move.l    _DosBase,a6
  2747.     lea    (.pic962,pc),a0
  2748.     move.l    a0,d1
  2749.     moveq    #ACCESS_READ,d2
  2750.     call    Lock
  2751.     move.l    d0,d1
  2752.     beq.b    .notp96
  2753.     call    UnLock
  2754.  
  2755.     lea    (.picasso96api,pc),a1
  2756.     moveq    #0,d0
  2757.     call    OpenLibrary
  2758.     tst.l    d0
  2759.     beq.b    .notp96
  2760.     move.l    d0,a1
  2761.     call    CloseLibrary
  2762.  
  2763.     moveq    #4,d7
  2764.     bra    .exit
  2765. .notp96
  2766.     lea    (.cybergfx,pc),a1
  2767.     lea    (LibList,a6),a0
  2768.     call    FindName
  2769. ;    moveq    #0,d0
  2770. ;    call    OpenLibrary
  2771.     tst.l    d0
  2772.     beq.b    .notgg
  2773. ;    move.l    d0,a1
  2774. ;    call    CloseLibrary
  2775.     move.l    _ThisTask,a3
  2776.     lea    (pr_WindowPtr,a3),a3
  2777.     move.l    (a3),d3
  2778.     moveq    #-1,d0
  2779.     move.l    d0,(a3)
  2780.     move.l    _DosBase,a6
  2781.     lea    (.cybergfx3,pc),a0
  2782.     move.l    a0,d1
  2783.     moveq    #ACCESS_READ,d2
  2784.     call    Lock
  2785.     move.l    d0,d1
  2786.     bne.b    .isgg
  2787.     lea    (.cybergfx2,pc),a0
  2788.     move.l    a0,d1
  2789.     call    Lock
  2790.     move.l    d0,d1
  2791.     beq.b    .notgg2
  2792. .isgg    call    UnLock
  2793.     move.l    d3,(a3)
  2794.     moveq    #3,d7
  2795.     bra.b    .exit
  2796. .notgg2    move.l    d3,(a3)
  2797. .notgg
  2798.     move.l    (ExecBase00,pc),a6
  2799.  
  2800.     lea    (.retina,pc),a1
  2801.     lea    (LibList,a6),a0
  2802.     call    FindName
  2803.     tst.l    d0
  2804.     beq.b    .not_retina
  2805.     moveq    #7,d7
  2806.     move.l    #$4754<<16+6,d0        Try to find Retina Z2
  2807.     bsr    FindConfigDev
  2808.     bne.b    .exit
  2809.     move.l    #$4754<<16+16,d0    Try to find Retina Z3
  2810.     bsr    FindConfigDev
  2811.     bne.b    .exit
  2812. .not_retina
  2813.     lea    (.egs,pc),a1
  2814.     moveq    #6,d7
  2815.     bsr.b    .test
  2816.     lea    (.graffiti,pc),a1
  2817.     moveq    #8,d7
  2818.     bsr.b    .test
  2819.     lea    (.tiga,pc),a1
  2820.     moveq    #9,d7
  2821.     bsr.b    .test
  2822.     lea    (.probench,pc),a1
  2823.     moveq    #5,d7
  2824.     bsr.b    .test
  2825.  
  2826.     moveq    #0,d7
  2827. .exit    tst.l    d7
  2828.     beq.b    .none
  2829.     move.l    d7,(sp)
  2830. .none    movem.l    (sp)+,d0-a6
  2831.     rts
  2832.  
  2833. .test
  2834. ;    moveq    #0,d0
  2835. ;    call    OpenLibrary
  2836.     lea    (LibList,a6),a0
  2837.     call    FindName
  2838.     tst.l    d0
  2839.     beq.b    .texit
  2840. ;    move.l    d0,a1
  2841. ;    call    CloseLibrary
  2842.     move.l    #.exit,(sp)
  2843. .texit    rts
  2844.  
  2845. .picassortg    dc.b    'rtg.library',0
  2846. .pic962    dc.b    'DEVS:Picasso96Settings',0
  2847. .picasso96api    dc.b    'Picasso96API.library',0
  2848. .cybergfx    dc.b    'cybergraphics.library',0
  2849. .cybergfx2    dc.b    'ENVARC:CyberGraphics',0
  2850. .cybergfx3    dc.b    'ENVARC:CyberGraphX',0
  2851. .egs    dc.b    'egs.library',0
  2852. .retina    dc.b    'retina.library',0
  2853. .graffiti    dc.b    'graffiti.library',0
  2854. .tiga    dc.b    'gfx.library',0
  2855. .probench    dc.b    'hrgblitter.library',0
  2856.     CNOP    0,4
  2857.  
  2858.  
  2859. ; OUT: D0.l=size of virtual memory in KB
  2860. GetVirtMem    movem.l    d1/a0-a1/a6,-(sp)
  2861.     move.l    (ExecBase00,pc),a6
  2862.     lea    (.vmemname,pc),a1
  2863.     moveq    #1,d0
  2864.     call    OpenLibrary
  2865.     tst.l    d0
  2866.     beq.b    .novmem
  2867.     move.l    d0,a6
  2868.     moveq    #1,d0            VMEMF_VIRTUAL
  2869.     move.l    #MEMF_TOTAL,d1
  2870.     jsr    (-$2A,a6)        VMAvailMem
  2871.     move.l    d0,-(sp)
  2872.     move.l    a6,a1
  2873.     move.l    (ExecBase00,pc),a6
  2874.     call    CloseLibrary
  2875.     move.l    (sp)+,d0
  2876. .novmem    movem.l    (sp)+,d1/a0-a1/a6
  2877.     beq.b    .getit
  2878.     movem.l    d1-d2,-(sp)
  2879.     move.l    d0,d1
  2880.     swap    d1
  2881.     and.l    #$0FFFF,d1
  2882.     divu.w    #1024,d1
  2883.     swap    d1
  2884.     clr.w    d1
  2885.     move.l    d1,d2
  2886.     lsl.l    #8,d2
  2887.     lsl.l    #2,d2
  2888.     sub.l    d2,d0
  2889.     divu.w    #1024,d0
  2890.     and.l    #$0FFFF,d0
  2891.     add.l    d1,d0
  2892.     movem.l    (sp)+,d1-d2
  2893.     rts
  2894.  
  2895. .getit    move.l    #(MEMF_PUBLIC!MEMF_CHIP!MEMF_LOCAL!MEMF_24BITDMA!MEMF_KICK)<<16+(MEMF_ANY),d0
  2896.     bra.b    GetMem
  2897.  
  2898. .vmemname    dc.b    'vmem.library',0
  2899.     CNOP    0,4
  2900.  
  2901. ; OUT: D0.l=size of fast memory in KB
  2902. GetFastMem    move.l    #(MEMF_PUBLIC!MEMF_CHIP!MEMF_FAST)<<16+(MEMF_PUBLIC!MEMF_FAST),d0
  2903.     bra.b    GetMem
  2904.  
  2905. ; OUT: D0.l=size of chip memory in KB
  2906. GetChipMem    move.l    #(MEMF_PUBLIC!MEMF_CHIP!MEMF_FAST)<<16+(MEMF_PUBLIC!MEMF_CHIP),d0
  2907. ;    bra.b    GetMem
  2908.  
  2909. ;  IN: d0=mask, d1=req
  2910. ; OUT: D0.l=total size of memory with matching 'req' after masking req with 'mask'
  2911. GetMem    movem.l    d1-d3/a0/a6,-(sp)
  2912.     move.w    d0,d3
  2913.     swap    d0
  2914.     move.w    d0,d2
  2915.     and.w    d2,d3
  2916.     move.l    (ExecBase00,pc),a6
  2917.     call    Forbid
  2918.  
  2919.     move.l    (MemList,a6),a0
  2920.     moveq    #0,d0
  2921. .loop    move.l    (a0),d1
  2922.     beq.b    .done
  2923.     move.w    (MH_ATTRIBUTES,a0),d1
  2924.     and.w    d2,d1
  2925.     cmp.w    d3,d1
  2926.     bne.b    .nomatch
  2927.     move.l    (MH_UPPER,a0),d1
  2928.     sub.l    (MH_LOWER,a0),d1
  2929.     subq.l    #1,d1
  2930.     lsr.l    #8,d1
  2931.     lsr.l    #6,d1
  2932.     addq.l    #1,d1
  2933.     lsl.l    #4,d1
  2934.     add.l    d1,d0
  2935. .nomatch    move.l    (a0),a0
  2936.     bra.b    .loop
  2937. .done
  2938.     call    Permit
  2939.     movem.l    (sp)+,d1-d3/a0/a6
  2940.     rts
  2941.  
  2942.  
  2943. ; OUT: D0=version<<16+revision, or null if wblib
  2944. GetWBVersion    movem.l    d1-a6,-(sp)
  2945.     moveq    #0,d7
  2946.     move.l    (ExecBase00,pc),a6
  2947.     lea    (.versionname,pc),a1
  2948.     moveq    #0,d0
  2949.     call    OpenLibrary
  2950.     tst.l    d0
  2951.     beq.b    .exit
  2952.     move.l    d0,a1
  2953.     move.l    (LIB_VERSION,a1),d7
  2954.     call    CloseLibrary
  2955. .exit    move.l    d7,d0
  2956.     movem.l    (sp)+,d1-a6
  2957.     rts
  2958. .versionname    dc.b    'version.library',0
  2959.     CNOP    0,4
  2960.  
  2961.  
  2962.     STRUCTURE prvSetPatchSemaphore,0
  2963.     STRUCT    prvsps_Sem,SS_SIZE
  2964.     STRUCT    prvsps_Private,MLH_SIZE
  2965.     UWORD    prvsps_Version
  2966.     UWORD    prvsps_Revision
  2967.     ; Don't touch
  2968. GetSetPatchVersion
  2969.     movem.l    d1-a6,-(sp)
  2970.     moveq    #0,d7
  2971.     move.l    (ExecBase00,pc),a6
  2972.     cmp.w    #36,(LIB_VERSION,a6)
  2973.     blo.b    .exit
  2974.     lea    (.semaname,pc),a1
  2975.     call    Forbid
  2976.     call    FindSemaphore
  2977.     call    Permit
  2978.     tst.l    d0
  2979.     beq.b    .exit
  2980.     move.l    d0,a0
  2981.     move.l    (prvsps_Version,a0),d7
  2982. .exit    move.l    d7,d0
  2983.     movem.l    (sp)+,d1-a6
  2984.     rts
  2985. .semaname    dc.b    '« SetPatch »',0
  2986.     CNOP    0,4
  2987.  
  2988. ; OUT: D0=version<<16+revision
  2989. ;      d1=chksum
  2990. GetCRomVer    movem.l    d2-d3/a0-a1/a6,-(sp)
  2991.     move.l    (ExecBase00,pc),a6
  2992.  
  2993.     move.l    (LIB_IDSTRING,a6),d0
  2994.     and.w    #~3,d0
  2995.     move.l    d0,a0
  2996.     move.l    #$11104EF9,d0
  2997.     move.l    #$FFF8FFFF,d1
  2998.     moveq    #-1,d3
  2999.  
  3000.     move.l    a0,a1
  3001. .find    move.l    -(a0),d2
  3002.     and.l    d1,d2
  3003.     cmp.l    d2,d0
  3004.     dbeq    d3,.find
  3005.     addq.w    #1,d3
  3006.     bne.b    .addrok
  3007.     move.l    a1,d0
  3008.     clr.w    d0               Commodore does it this way...
  3009.     move.l    d0,a0
  3010. .addrok
  3011. ;;    lea    ($1000).w,a1
  3012. ;;    move.l    (a1),(a1)        <- Fake access (NOT enforcer hit, though)
  3013.     move.l    (12,a0),d3
  3014.  
  3015.     move.l    #256*1024,d0
  3016.     cmp.w    #$1111,(a0)
  3017.     beq.b    .rom256k
  3018.     add.l    d0,d0
  3019. .rom256k    jsr    ROMReSum
  3020.     move.l    d0,d1
  3021.  
  3022.     move.l    d3,d0
  3023.     movem.l    (sp)+,d2-d3/a0-a1/a6
  3024.     rts
  3025.  
  3026.  
  3027. ;  IN: D0.w=attnflags
  3028. ; OUT: D0=version<<16+revision, zero if no "real" KS rom available
  3029. ;      d1=chksum, zero if no "real" KS rom available
  3030. GetChipRomVer    movem.l    d2-d7/a0-a6,-(sp)
  3031.     move.l    (ExecBase00,pc),a6
  3032.  
  3033.     jsr    getromver_novmem
  3034.  
  3035.     move.l    d6,d1
  3036.     move.l    d7,d0
  3037.     movem.l    (sp)+,d2-d7/a0-a6
  3038.     rts
  3039.  
  3040.  
  3041. ; OUT: D0=chipid, -1=unknown
  3042. GetAnimChip    movem.l    d1-d7/a0-a6,-(sp)
  3043.     moveq    #-1,d7
  3044.     tst.l    NoHW
  3045.     bne.b    .xit
  3046.  
  3047.     moveq    #1,d7
  3048.     move.w    $DFF004,d0
  3049.     and.w    #$7F00,d0
  3050.     lsr.w    #8,d0
  3051.     bclr    #4,d0
  3052.     beq.b    .skip
  3053.     moveq    #0,d7
  3054. .skip
  3055.     cmp.b    #$20,d0
  3056.     beq.b    .sa4
  3057.     cmp.b    #$21,d0
  3058.     beq.b    .sa6
  3059.     cmp.b    #$22,d0
  3060.     beq.b    .sa8
  3061.     cmp.b    #$23,d0
  3062.     beq.b    .saA
  3063.  
  3064.     tst.b    d0
  3065.     bne.b    .unknown
  3066.     bsr.b    .subr
  3067.     bra.b    .xit
  3068.  
  3069. .saA    addq.b    #2,d7
  3070. .sa8    addq.b    #2,d7
  3071. .sa6    addq.b    #2,d7
  3072. .sa4    addq.b    #4,d7
  3073.  
  3074. .xit    move.l    d7,d0
  3075.     movem.l    (sp)+,d1-d7/a0-a6
  3076.     rts
  3077.  
  3078. .unknown    moveq    #-1,d7
  3079.     bra.b    .xit
  3080.  
  3081. .subr    move.l    (ExecBase00,pc),a6    Test for 8361/8367 Agnus:
  3082.     call    Disable
  3083.     moveq    #32-1,d6        Multicheck: 32 times
  3084.     move.l    _GfxBase,a6
  3085.     lea    $DFF000,a5        Loads of preloads:
  3086.     lea    (bltsize,a5),a4
  3087.     lea    (dmaconr,a5),a3
  3088.     moveq    #$41,d4            Shortest possible blit
  3089.     call    OwnBlitter
  3090.     move.w    (a3),d5            Save dmacon
  3091.     move.w    #DMAF_BLITHOG,(dmacon,a5) <- No nasty blitter, please!
  3092. .blitloop    call    WaitBlit        Do it right, but only here! :-O
  3093.     move.w    #$0E00,(bltcon0,a5)    Dummy blit, no dest
  3094.     bra.b    .blitcnop
  3095.     CNOP    0,4            Align to longword
  3096. .blitcnop    move.w    d4,(a4)            / Fetched in   \
  3097.     move.w    (a3),d0            \ one longword /
  3098.     btst    #DMAB_BLTDONE,d0    <- _Very_ old agnus
  3099.     beq.b    .old_agnus           get this wrong!!!
  3100.     dbf    d6,.blitloop
  3101.     addq.b    #2,d7
  3102. .old_agnus    or.w    #$8000,d5        Restore dmacon
  3103.     move.w    d5,(dmacon,a5)
  3104.     call    WaitBlit        Wait blit to finish, if any
  3105.     call    DisownBlitter
  3106.     move.l    (ExecBase00,pc),a6
  3107.     call    Enable
  3108.     rts
  3109.  
  3110.  
  3111. ;  \/  Now this should work with OCS *much* better!?  \/
  3112.  
  3113. ; OUT: D0=chipid, 0=OCS denise, 1=ECS denise, 2=AGA Lisa, 3=AAA Lisa, 4=Unknown
  3114. ;      d1.w=revision number, or -1 if OCS
  3115. GetGfxChip    movem.l    d2-d3/d7/a0/a5/a6,-(sp)
  3116.     moveq    #-1,d1
  3117.     moveq    #4,d0
  3118.     tst.l    NoHW
  3119.     bne.b    .exit
  3120.     lea    $DFF000,a5
  3121.     move.l    (ExecBase00,pc),a6
  3122.     call    Disable
  3123.     moveq    #0,d7
  3124.     lea    ($7C,a5),a0        Preload denise/lisa ID hw addr
  3125.     move.w    #$FF,d3            Preload 'and' value
  3126.  
  3127.     moveq    #1-1,d0            !! These two just disable the
  3128.     bsr    HWWait            !! annoying flick effect...
  3129.     move.w    (dmaconr,a5),d1        Save old dmacon
  3130.     or.w    #DMAF_SETCLR,d1
  3131.     move.w    #$3FF,(dmacon,a5)    Disable all dma
  3132.     move.w    (a0),d0            !! OCS denise gives value $FFFF 
  3133.                     ;! when all dma is off (hmm?)
  3134.     move.w    d1,(dmacon,a5)        Enable dma again
  3135.     not.w    d0            !! Well, my old trusty A500 does!!
  3136.     beq.b    .OCS            !! (CAN'T BE SURE ABOUT THIS)
  3137.  
  3138.     move.w    (a0),d0             Get ID
  3139.     and.w    d3,d0
  3140.     moveq    #128-1,d2        Check 128 times (try to notice old denise random)
  3141. .loop    move.w    (a0),d1            Get ID again
  3142.     and.w    d3,d1
  3143.     cmp.b    d0,d1            Same value?
  3144.     bne.b    .OCS            Not the same value, then OCS Denise
  3145.     dbf    d2,.loop
  3146.     cmp.b    #$FC,d0
  3147.     beq.b    .ECS
  3148.     or.b    #%11110000,d0        Mask AGA revision
  3149.     cmp.b    #%11111000,d0        Bit 3=AGA
  3150.     beq.b    .AGA
  3151.     cmp.b    #%11110000,d0        Bit 3=0 => AAA
  3152.     beq.b    .AAA
  3153.     addq.l    #1,d7            4 is Unknown
  3154. .AAA    addq.l    #1,d7            3 is AAA
  3155. .AGA    addq.l    #1,d7            2 is AGA
  3156. .ECS    addq.l    #1,d7            1 is ECS
  3157. .OCS    move.l    d7,d0            0 is OCS
  3158.  
  3159.     call    Enable
  3160.  
  3161.     tst.b    d0
  3162.     beq.b    .skip_OCS
  3163.     and.w    #%11110000,d1
  3164.     lsr.b    #4,d1
  3165.     neg.b    d1
  3166.     add.b    #$F,d1
  3167.  
  3168. .exit    movem.l    (sp)+,d2-d3/d7/a0/a5/a6
  3169.     rts
  3170.  
  3171. .skip_OCS    moveq    #-1,d1
  3172.     bra.b    .exit
  3173.  
  3174.  
  3175. ;  IN: A0=FmtString, A1=Array, a2=Buffer
  3176. ; OUT: Formatted text
  3177. Sprintf    movem.l    a0-a3/a6/d0-d1,-(sp)
  3178.     move.l    a2,a3
  3179.     lea    (.putchar,pc),a2
  3180.     move.l    (ExecBase00,pc),a6
  3181.     call    RawDoFmt
  3182.     movem.l    (sp)+,a0-a3/a6/d0-d1
  3183.     rts
  3184. .putchar    move.b    d0,(a3)+
  3185.     rts
  3186.  
  3187.  
  3188. ;  IN: A0=FmtString, A1=Array (may be 0)
  3189. ; OUT: Printed text
  3190. Printf    movem.l    a0-a3/a6/d0-d3,-(sp)
  3191.     lea    pf_Data,a3
  3192.     move.l    a5,(a3)+
  3193.     clr.l    (a3)+
  3194.     lea    (.newchar,pc),a2
  3195.     move.l    (ExecBase00,pc),a6
  3196.     call    RawDoFmt
  3197.     move.l    a5,a6
  3198.     move.l    OutputFH,d1
  3199.     move.l    a3,d2
  3200.     move.l    (-4,a3),d3
  3201.     call    Write
  3202.     movem.l    (sp)+,a0-a3/a6/d0-d3
  3203.     rts
  3204. .newchar    movem.l    d0-d3/a0-a1/a3/a6,-(sp)
  3205.     move.l    a3,d2                for Write()
  3206.     move.l    -(a3),d1
  3207.     move.b    d0,4(a3,d1.l)
  3208.     addq.b    #1,d1
  3209.     move.l    d1,(a3)
  3210.     bne.b    .dont_print
  3211.     move.l    -(a3),a6
  3212.     move.l    OutputFH,d1
  3213.     moveq    #64,d3
  3214.     lsl.w    #2,d3
  3215.     call    Write
  3216. .dont_print    movem.l    (sp)+,d0-d3/a0-a1/a3/a6
  3217.     rts
  3218.  
  3219.  
  3220. ; a0=timer routine (should be in chipmem)
  3221. ; OUT: D0.l=compare time
  3222. DoTimer    movem.l    d1-a6,-(sp)
  3223.     move.l    a0,a5
  3224.     lea    $DFF000,a4
  3225.     move.l    (ExecBase00,pc),a6
  3226.  
  3227.     move.l    _ThisTask,a1
  3228.     moveq    #127,d0
  3229.     call    SetTaskPri
  3230.     move.l    d0,-(sp)
  3231.  
  3232.     cmp.w    #4,BandWidth
  3233.     beq.b    .is_aga4x
  3234.     move.l    a6,-(sp)
  3235.     move.l    _GfxBase,a6
  3236.     move.l    (gb_ActiView,a6),d6    save view
  3237.     sub.l    a1,a1
  3238.     call    LoadView
  3239.     moveq    #3-1,d0
  3240.     bsr    HWWait
  3241.     move.l    (sp)+,a6
  3242. .is_aga4x
  3243.     move.l    a6,-(sp)
  3244.     move.l    _GfxBase,a6
  3245.     call    WaitBlit        Wait possible blit to finish.
  3246.     move.l    (sp)+,a6
  3247.  
  3248.     jsr    ChipTiming2
  3249.     move.l    d0,d7
  3250.  
  3251.     cmp.w    #4,BandWidth        Restore view, if needed
  3252.     beq.b    .is_aga4x2
  3253.     move.l    a6,-(sp)
  3254.     move.l    _GfxBase,a6
  3255.     move.l    d6,a1
  3256.     call    LoadView
  3257.     moveq    #3-1,d0
  3258.     bsr    HWWait
  3259. ;;    move.l    (gb_copinit,a6),(cop1lc,a4)    Kick copper into life
  3260.     move.l    (sp)+,a6
  3261. .is_aga4x2
  3262.     move.l    _ThisTask,a1
  3263.     move.l    (sp)+,d0
  3264.     call    SetTaskPri
  3265.  
  3266.     move.l    d7,d0
  3267.     movem.l    (sp)+,d1-a6
  3268.     rts
  3269.  
  3270.  
  3271.  
  3272. HWWait    movem.l    d0-d2/a0,-(sp)
  3273.     tst.l    NoHW
  3274.     bne.b    .nohw
  3275.     lea    $DFF006,a0
  3276.     moveq    #-1,d2
  3277. .wait1    move.b    (a0),d1
  3278.     cmp.b    d2,d1
  3279.     bne.b    .wait1
  3280. .wait2    move.b    (a0),d1
  3281.     cmp.b    d2,d1
  3282.     beq.b    .wait2
  3283.     dbf    d0,.wait1
  3284. .exit    movem.l    (sp)+,d0-d2/a0
  3285.     rts
  3286.  
  3287. .nohw    addq.l    #1,d0
  3288.     bsr    WaitBlanks        Will break Forbid() or Disable()
  3289.     bra.b    .exit
  3290.  
  3291.  
  3292. ; OUT: d0=iCRBit (now result is LONG negative if failed to get cia)
  3293. InitTimer    movem.l    d1/d7/a0-a1/a5-a6,-(sp)
  3294.     move.l    (ExecBase00,pc),a6
  3295.     moveq    #-1,d7            for .noresource
  3296.     lea    (_CiabName,pc),a1
  3297.     call    OpenResource
  3298.     move.l    d0,CiabResource
  3299.     beq.b    .noresource
  3300.     move.l    d0,a5
  3301.  
  3302.     moveq    #IS_SIZE,d0
  3303.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    No virtmem please!
  3304.     call    AllocMem
  3305.     move.l    d0,_CiaInterrupt
  3306.     beq.b    .nomem
  3307.  
  3308.     move.l    d0,a1
  3309.     addq.l    #LN_TYPE,a1
  3310.     move.w    #NT_INTERRUPT<<8+127,(a1)+
  3311.     lea    (CiaIntName,pc),a0
  3312.     move.l    a0,(a1)+
  3313.     lea    CiaIntData,a0
  3314.     move.l    a0,(a1)+
  3315.     lea    CiaIntCode,a0
  3316.     move.l    a0,(a1)+
  3317.  
  3318.     moveq    #1,d7
  3319. .allocloop    move.l    d7,d0
  3320.      move.l    _CiaInterrupt,a1
  3321.     exg    a5,a6
  3322.     call    AddICRVector
  3323.     exg    a5,a6
  3324.     tst.l    d0
  3325.     beq.b    .ciaok
  3326.     dbf    d7,.allocloop
  3327. .ciaok
  3328.     tst.w    d7
  3329.     bpl.b    .gottimer
  3330.     move.l    _CiaInterrupt,a1
  3331.     clr.l    _CiaInterrupt
  3332.     moveq    #IS_SIZE,d0
  3333.     call    FreeMem
  3334. .gottimer
  3335. .nomem
  3336. .noresource    move.w    d7,d0
  3337.     ext.l    d0
  3338.     movem.l    (sp)+,d1/d7/a0-a1/a5-a6
  3339.     rts
  3340.  
  3341. ;  IN: d0=iCRBit
  3342. RemTimer    movem.l    d0-d1/a0-a1/a6,-(sp)
  3343.     tst.l    d0
  3344.     bmi.b    .exit
  3345.     move.l    CiabResource,d1
  3346.     beq.b    .xit
  3347.     move.l    d1,a6
  3348.     move.l    _CiaInterrupt,a1
  3349.     call    RemICRVector
  3350.     move.l    (ExecBase00,pc),a6
  3351.     move.l    _CiaInterrupt,a1
  3352.     clr.l    _CiaInterrupt
  3353.     moveq    #IS_SIZE,d0
  3354.     call    FreeMem    
  3355. .exit    clr.l    CiabResource
  3356. .xit    movem.l    (sp)+,d0-d1/a0-a1/a6
  3357.     rts
  3358.  
  3359. EvaluateFormulas
  3360. ;    move.l    #MC68060,CPUID        debug
  3361. ;    clr.l    CardSlotID
  3362. ;    st    A4000ID
  3363.  
  3364.     movem.l    d1-d7/a0-a6,-(sp)
  3365.     move.l    sp,EvalSpSave
  3366.     moveq.l    #0,d6            param array
  3367.     lea    (Formulas,pc),a1
  3368. .get_next    move.l    (a1)+,a0
  3369. ;    beq.b    _eval_error        <- n_e_v_e_r happens!!
  3370. ;    move.l    d0,a0
  3371.     move.l    a1,-(sp)
  3372.     bsr.b    _EvaluateFormula
  3373.     move.l    (sp)+,a1
  3374.     tst.l    d0
  3375.     beq.b    .get_next
  3376.     move.l    (a0),d0
  3377.     cmp.l    #32,d0
  3378.     bhs.b    _eval_exit
  3379.     bset    d0,d6
  3380.     bra.b    .get_next
  3381. _eval_exit
  3382. _eval_error
  3383. ;;    move.l    d6,WAIndex        db
  3384.     move.l    EvalSpSave,sp
  3385. ;    tst.l    d0            disabled - zero not possible!
  3386. ;    bne.b    .ok
  3387. ;    lea    (sNullStr,pc),a0
  3388. ;    move.l    a0,d0
  3389. ;.ok
  3390.     movem.l    (sp)+,d1-d7/a0-a6
  3391.     rts
  3392. _eval_error2    lea    (sEvalErr,pc),a0
  3393.     move.l    a0,d0
  3394.     bra.b    _eval_error
  3395.  
  3396. ; A1=parameter array
  3397. _EvaluateFormula2
  3398.     move.l    a0,-(sp)
  3399.     move.l    a1,a0
  3400.     bsr.b    _EvaluateFormula
  3401.     move.l    (sp)+,a0
  3402.     rts
  3403.  
  3404. ; A0=parameter array
  3405. _EvaluateFormula
  3406.     moveq    #0,d0            orig result=0
  3407.     moveq    #0,d4            op-mode (AND)
  3408.     moveq    #0,d7            skipmode=OFF
  3409. .get_next_com    move.l    (a0)+,d1
  3410.     lea    (OperatorTable-8,pc),a1
  3411. .get_next_op    addq.l    #8,a1
  3412.     move.l    (a1)+,d2
  3413.     beq.b    _eval_error2
  3414.     cmp.l    d1,d2
  3415.     bne.b    .get_next_op
  3416.     move.l    (4,a1),a2
  3417.     movem.l    (a0),d1-d3
  3418.     add.l    (a1),a0
  3419.     cmpa.w    #0,a2
  3420.     beq.b    .evaluated
  3421.     tst.b    d7            handle skip-mode
  3422.     bne.b    .get_next_com        << fixed!
  3423.     tst.l    (a1)            handle first parameter
  3424.     beq.b    .not_addr_arg
  3425.     move.l    d1,a1
  3426.     cmp.l    #_EvaluateFormula2,a2    special handle for jump command
  3427.     beq.b    .not_addr_arg    
  3428.     cmpa.w    #32,a1
  3429.     bhs.b    .std_addr_arg
  3430.     btst    d1,d6            test entry in param array
  3431.     sne    d1
  3432.     ext.w    d1
  3433.     ext.l    d1            d1.l=0/-1
  3434.     bra.b    .not_addr_arg
  3435. .std_addr_arg    move.l    (a1),d1
  3436. .not_addr_arg    moveq    #0,d0
  3437.     movem.l    d4-d7/a1-a6,-(sp)
  3438.     jsr    (a2)
  3439.     movem.l    (sp)+,d4-d7/a1-a6
  3440.     tst.l    d0
  3441.     beq.b    .d0zero
  3442.     moveq    #-1,d0            ensure d0=-1 on true-condition    
  3443. .d0zero    cmp.b    d4,d0
  3444.     bne.b    .no_cond_satisfied
  3445.     moveq    #-1,d7
  3446. .no_cond_satisfied
  3447.     bra    .get_next_com
  3448. .evaluated    rts
  3449.  
  3450. _EqualTo0    tst.l    d1
  3451.     seq    d0
  3452.     rts
  3453.  
  3454. _NotEqualTo0    tst.l    d1
  3455.     sne    d0
  3456.     rts
  3457.  
  3458. _Equal    cmp.l    d1,d2
  3459.     seq    d0
  3460.     rts
  3461.  
  3462. _InsideBorders    cmp.l    d2,d1
  3463.     blt.b    .no_inside
  3464.     cmp.l    d3,d1
  3465.     sle    d0
  3466. .no_inside    rts
  3467.  
  3468. _OutsideBorders    cmp.l    d2,d1
  3469.     blt.b    .is_outside
  3470.     cmp.l    d3,d1
  3471.     sle    d0
  3472. .is_outside    not.b    d0
  3473.     rts
  3474.  
  3475. _NotEqual    cmp.l    d1,d2
  3476.     sne    d0
  3477.     rts
  3478.  
  3479. _SetAndMode    moveq    #0,d4            AND-mode
  3480.     moveq    #-1,d0            result
  3481.     rts
  3482.  
  3483. _SetOrMode    moveq    #-1,d4            OR-mode
  3484.     moveq    #0,d0            result
  3485.     rts
  3486.  
  3487. OperatorTable    dc.l    '&',0,_SetAndMode
  3488.     dc.l    '!',0,_SetOrMode
  3489.     dc.l    '(',0,_EvaluateFormula
  3490.     dc.l    '->',4,_EvaluateFormula2
  3491.     dc.l    '=0',4,_EqualTo0
  3492.     dc.l    '<>0',4,_NotEqualTo0
  3493.     dc.l    '=',8,_Equal
  3494.     dc.l    '<>',8,_NotEqual
  3495.     dc.l    '<x<',12,_InsideBorders        the edges are included
  3496.     dc.l    'out',12,_OutsideBorders    the edges aren't included
  3497.     dc.l    ')',0,0
  3498.     dc.l    '|',0,0
  3499.     dc.l    0
  3500.  
  3501. _bitn    SET    0
  3502. BIT    MACRO
  3503. \1    EQU    _bitn
  3504. _bitn    SET    _bitn+1
  3505.     ENDM
  3506.  
  3507. ; Define toggle-array bits
  3508.     BIT    _ISAGA
  3509.  
  3510. Formulas    dc.l    calculateAGA
  3511.  
  3512.     dc.l    calculateDraCo
  3513.     dc.l    calculateCD32
  3514.     dc.l    calculateCDTV
  3515.     dc.l    calculateA1400
  3516.     dc.l    calculateA1200
  3517. ;X    dc.l    calculateWalker
  3518.     dc.l    calculateA4000T
  3519.     dc.l    calculateA4000
  3520.     dc.l    calculateA600
  3521.     dc.l    calculateA1000
  3522.     dc.l    calculateA3000
  3523.     dc.l    calculateA30UX
  3524.     dc.l    calculateA3000T
  3525.     dc.l    calculate2500
  3526.     dc.l    calculate500o
  3527.     dc.l    calculateA500e
  3528.     dc.l    calculateA2000e
  3529.     dc.l    calculateA500pe
  3530.     dc.l    calculateA2000pe
  3531.     dc.l    calculateA500p
  3532.     dc.l    calculateA2000p
  3533.     dc.l    calculateA500
  3534.     dc.l    calculateA2000
  3535.     dc.l    calculateAAA
  3536.  
  3537. ;    dc.l    calculateA1200        debug move! (ought to be before Walker)
  3538.  
  3539.     dc.l    calc_default        <- ALWAYS exits
  3540. ;    dc.l    0            <- Not needed!!
  3541.  
  3542. calculateAGA    dc.l    '&','=',GfxChipID,2,'<x<',AnimChipID,8,$B,'|',_ISAGA
  3543. calculateDraCo    dc.l    '&','<>0',DraCoID,'|',sDraCo
  3544. calculateCD32    dc.l    '&','<>0',C2PID,'<>0',_ISAGA,'<>0',CD32NVRAMID
  3545.     dc.l    '<x<',RomVer,40<<16,INFINITE,'<x<',CPUID,MIN020,MAXCPU,'|',sCD32
  3546. calculateCDTV    dc.l    '&','<x<',ChipMem,1024,2048,'<>0',CDTVID,'<x<',CPUID,0,MAX040,'|',sCDTV
  3547. calculateA1400    dc.l    '&','<x<',CPUID,MIN020,MAX020,'<x<',_100kHz,240,260,'=',ChipMem,2048
  3548.     dc.l    '<>0',_ISAGA,'<>0',CardSlotID
  3549.     dc.l    '<x<',RomVer,39<<16,INFINITE,'|',sAmiga1400
  3550. calculateA1200    dc.l    '&','<>0',_ISAGA,'<>0',CardSlotID,'<x<',CPUID,MIN020,MAXCPU
  3551.     dc.l    '<x<',RomVer,30<<16,INFINITE,'<x<',ChipMem,1024,2048,'|',sAmiga1200
  3552. ;??                 ^^
  3553. ;XcalculateWalker    dc.l    '&','<>0',_ISAGA,'<x<',RomVer,41<<16,INFINITE,'=0',CardSlotID
  3554. ;??                          ^^
  3555. ;X    dc.l    '=',CPUID,MC68EC030,'=',_100kHz,400,'<x<',ChipMem,1024,2048,'|',sWalker
  3556. calculateA4000T    dc.l    '&','<>0',_ISAGA,'<x<',RomVer,40<<16,INFINITE,'=0',CardSlotID
  3557. ;??                          ^^
  3558.     dc.l    '<x<',CPUID,MAX040,MAXCPU,'=',ChipMem,2048,'<>0',A4000TID,'|',sAmiga4000T
  3559. calculateA4000    dc.l    '&','<>0',_ISAGA,'<x<',RomVer,39<<16,INFINITE,'=0',CardSlotID
  3560.     dc.l    '<x<',CPUID,MIN030,MAXCPU,'=',ChipMem,2048,'<>0',A4000ID,'|',sAmiga4000
  3561. calculateA600    dc.l    '&','=',GfxChipID,1,'<x<',AnimChipID,6,7
  3562.     dc.l    '<x<',RomVer,37<<16+175+1,INFINITE,'<x<',ChipMem,1024,2048
  3563.     dc.l    '<>0',CardSlotID,'|',sAmiga600
  3564. calculateA1000    dc.l    '&','=',GfxChipID,0,'<x<',AnimChipID,0,1
  3565.     dc.l    '<x<',RomVer,30<<16,INFINITE,'<x<',ChipMem,256,512,'|',sAmiga1000
  3566. calculateA3000    dc.l    '&','<x<',RomVer,35<<16,INFINITE,'=',GfxChipID,1
  3567.     dc.l    '<x<',AnimChipID,4,7,'<x<',ChipMem,1024,2048
  3568.     dc.l    '<x<',CPUID,MIN030,MAXCPU,'<>0',A3000ID,'|',sAmiga3000
  3569. calculateA30UX    dc.l    '&','<>0',UNIXID,'<x<',RomVer,35<<16,INFINITE,'=',GfxChipID,1
  3570.     dc.l    '<x<',AnimChipID,4,7,'<x<',ChipMem,1024,2048
  3571.     dc.l    '<x<',CPUID,MIN030,MAXCPU,'<>0',A3000ID,'|',sAmiga3000UX
  3572. calculateA3000T    dc.l    '&','<x<',RomVer,35<<16,INFINITE,'=',GfxChipID,1
  3573.     dc.l    '<x<',AnimChipID,4,7,'<x<',ChipMem,1024,2048
  3574.     dc.l    '<x<',CPUID,MIN030,MAXCPU,'<>0',A4000ID,'|',sAmiga3000T
  3575. calculate2500    dc.l    '&','<>0',A2500ID,'<x<',RomVer,33<<16,INFINITE,'=',GfxChipID,0
  3576.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,512,1024,'<x<',CPUID,MIN020,MAX030
  3577.     dc.l    '<x<',_100kHz,240,260,'|',sAmiga2500
  3578. calculate500o    dc.l    '&','<x<',RomVer,33<<16,INFINITE,'=',GfxChipID,0
  3579.     dc.l    '<x<',AnimChipID,2,3,'=',ChipMem,512,'|',sAmiga500old
  3580.  
  3581. calculateA500e    dc.l    '&','<>0',A500EID,'<x<',RomVer,33<<16,INFINITE,'=',GfxChipID,0
  3582.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,512,2048,'<x<',CPUID,0,MAX040
  3583.     dc.l    '|',sAmiga500e
  3584. calculateA2000e    dc.l    '&','<>0',A2000EID,'<x<',RomVer,33<<16,INFINITE,'=',GfxChipID,0
  3585.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,512,1024,'<x<',CPUID,0,MAXCPU
  3586.     dc.l    '|',sAmiga2000e
  3587. calculateA500pe    dc.l    '&','<>0',A500EID,'<x<',RomVer,37<<16,INFINITE,'=',GfxChipID,1
  3588.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,1024,2048,'<x<',CPUID,0,MAX040
  3589.     dc.l    '|',sAmiga500Pluse
  3590. calculateA2000pe
  3591.     dc.l    '&','<>0',A2000EID,'<x<',RomVer,37<<16,INFINITE,'=',GfxChipID,1
  3592.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,1024,2048,'<x<',CPUID,0,MAXCPU
  3593.     dc.l    '|',sAmiga2000Pluse
  3594. calculateA500p    dc.l    '&','=0',A500EID,'<x<',RomVer,37<<16,INFINITE,'=',GfxChipID,1
  3595.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,1024,2048,'<x<',CPUID,0,MAX040
  3596.     dc.l    '|',sAmiga500Plus
  3597. calculateA2000p    dc.l    '&','=0',A2000EID,'<x<',RomVer,37<<16,INFINITE,'=',GfxChipID,1
  3598.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,1024,2048,'<x<',CPUID,0,MAXCPU
  3599.     dc.l    '|',sAmiga2000Plus
  3600. calculateA500    dc.l    '&','=0',A500EID,'<x<',RomVer,33<<16,INFINITE,'=',GfxChipID,0
  3601.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,512,2048,'<x<',CPUID,0,MAX040
  3602.     dc.l    '|',sAmiga500
  3603. calculateA2000    dc.l    '&','=0',A2000EID,'<x<',RomVer,33<<16,INFINITE,'=',GfxChipID,0
  3604.     dc.l    '<x<',AnimChipID,4,5,'<x<',ChipMem,512,1024,'<x<',CPUID,0,MAXCPU
  3605.     dc.l    '|',sAmiga2000
  3606.  
  3607. calculateAAA    dc.l    '=',GfxChipID,3,'|',sAmigaAAA
  3608. calc_default    dc.l    '<>0',calc_default,'|',sDefault
  3609.  
  3610.  
  3611. GfxChipTable
  3612. .s    dc.w    sDenise-.s,sECSDenise-.s,sAGALisa-.s,sAAALisa-.s,sUnknown-.s
  3613.  
  3614.     dc.w    sUnknown-AnimChipTable
  3615. AnimChipTable
  3616. .s    dc.w    sA0-.s,sA1-.s,sA2-.s,sA3-.s,sA4-.s,sA5-.s,sA6-.s,sA7-.s
  3617.     dc.w    sA8-.s,sA9-.s,sAA-.s,sAB-.s
  3618.  
  3619. CPUTable
  3620. .s    dc.w    s68000-.s,s68010-.s,s68EC020-.s,s68020-.s,s68EC030-.s
  3621.     dc.w    s68030-.s,s68EC040-.s,s68LC040-.s,s68040-.s
  3622.     dc.w    s68EC060-.s,s68LC060-.s,s68060-.s
  3623. ;;    dc.w    sMPC603e-.s,sMPC604-.s,sMPC620-.s
  3624.  
  3625. FPUTable
  3626. .s    dc.w    sFna-.s,s68881-.s,s68882-.s,s68040f-.s,s68060f-.s
  3627.  
  3628. MMUTable
  3629. .s    dc.w    s68851-.s,s68030m-.s,s68040m-.s,s68060m-.s
  3630.  
  3631. GfxLibEmulTable
  3632. .s    dc.w    sOCS-.s,sECS-.s,sAGA-.s,sCyberGfxg-.s,sPicasso96g-.s,sProBenchg-.s
  3633.     dc.w    sEGSg-.s,sRetinag-.s,sGraffitig-.s,sTIGAg-.s,sAltaisg-.s
  3634.  
  3635. PowerPCTable
  3636. .s    dc.w    sPPCxx-.s,sPPCxx-.s,sPPCxx-.s
  3637.     dc.w    sPPC603-.s,sPPC604-.s,sPPC602-.s,sPPC603e-.s,sPPC603p-.s
  3638.     dc.w    sPPCxx-.s
  3639.     dc.w    sPPC604e-.s
  3640.  
  3641. PowerPCPLLTable
  3642. .s    dc.w    pllxx-.s,pllxx-.s,pllxx-.s
  3643.     dc.w    pll603-.s,pll604-.s,pll602-.s,pll603e-.s,pll603p-.s
  3644.     dc.w    pllxx-.s
  3645.     dc.w    pll604e-.s
  3646.  
  3647. pllxx
  3648. pll603
  3649. pll604
  3650. pll602
  3651. pll603e
  3652. pll603p
  3653. pll604e
  3654.     dc.w    10    ; 0000
  3655.     dc.w    10    ; 0001
  3656.     dc.w    70    ; 0010
  3657.     dc.w    10    ; 0011 PLL bypass
  3658.     dc.w    20    ; 0100
  3659.     dc.w    65    ; 0101
  3660.     dc.w    25    ; 0110
  3661.     dc.w    45    ; 0111
  3662.     dc.w    30    ; 1000
  3663.     dc.w    55    ; 1001
  3664.     dc.w    40    ; 1010
  3665.     dc.w    50    ; 1011
  3666.     dc.w    15    ; 1100
  3667.     dc.w    60    ; 1101
  3668.     dc.w    35    ; 1110
  3669.     dc.w    10    ; 1111
  3670.  
  3671.  
  3672. DosName    dc.b    'dos.library',0
  3673. ExpName    dc.b    'expansion.library',0
  3674. _GfxName    dc.b    'graphics.library',0
  3675. _CiabName    dc.b    'ciab.resource',0
  3676. CiaIntName    dc.b    'WhichAmiga CIA interrupt',0
  3677. TimerDevName    dc.b    'timer.device',0
  3678. ConsoleName    dc.b    'CON:10/10/620/246/ WhichAmiga  Copyright © 1995-1999 PitPlane Productions',0
  3679. NewConsoleName    dc.b    'CON:10/10/620/246/WhichAmiga  Copyright © 1995-1999 PitPlane Productions/CLOSE/AUTO/WAIT',0
  3680. PressReturn    dc.b    10,$9B,'0 pPress <RETURN> to close window.',$9B,'30;40m',0
  3681. sNoHW    dc.b    'No Amiga custom hardware available',0
  3682. sNotimer    dc.b    'Severe trouble! No free CIA timer available',10
  3683. sMhzxxxErr    dc.b    '%s!',10
  3684.     dc.b    'Unable to calculate %s clock frequency.',10,0
  3685. sCPU    dc.b    'CPU',0
  3686. sFPU    dc.b    'FPU',0
  3687. CursorOn    dc.b    $9B,' p',0
  3688.  
  3689.     dc.b    '$VER:'
  3690. sStart    dc.b    'WhichAmiga 1.3.3 (2.5.99)',10
  3691.     dc.b    $9B,'0 p'
  3692.     dc.b    'Written by Harry "Piru" Sintonen. Copyright © 1995-1999 PitPlane Productions.',10,10
  3693.     dc.b    'Evaluating system...',10,0
  3694.  
  3695. ;;sRaport    dc.b    'Central Processing Unit: %s %d.%d MHz  (%dx %s %dMHz WAIndex: %ld)',10
  3696. sRaport    dc.b    'Central Processing Unit: %s %d.%d MHz%s',10
  3697.     dc.b    '%s'
  3698.     dc.b    '    Floating Point Unit: %s',10
  3699.     dc.b    ' Memory Management Unit: %s %s',10
  3700.     dc.b    '   Custom graphics chip: %s%s',10
  3701.     dc.b    '  Custom animation chip: %s',10
  3702.     dc.b    '   Other custom chip(s): %s',10
  3703.     dc.b    '        Graphics system: %s%s',10
  3704.     dc.b    '%s%s'
  3705.     dc.b    '%s'
  3706.     dc.b    '%s%s'
  3707.     dc.b    '         Hardware Clock: %s',10
  3708.     dc.b    ' Max. Chipmem available: %ld K',10
  3709.     dc.b    ' Max. Fastmem available: %ld K',10
  3710.     dc.b    '%s'
  3711.     dc.b    '       ROM chip version: %d.%d (Kickstart %s)',10
  3712.     dc.b    '%s'
  3713.     dc.b    '      Workbench version: %d.%d (Workbench %s)',10
  3714.     dc.b    '       SetPatch version: %s',10
  3715.     dc.b    '%s'
  3716.     dc.b    10
  3717.     dc.b    ' Your computer %s%s.',10
  3718.     dc.b    0
  3719.  
  3720. sRev    dc.b    ' (rev %d)',0
  3721. sReKickROM    dc.b    '  ReKicked ROM, version: %d.%d (Kickstart %s)',10,0
  3722. sHWC2P    dc.b    '  Chunky-to-planar conv: available',10,0
  3723. sGfxBoards    dc.b    '      Graphics board(s): ',0
  3724. sSndCards    dc.b    '           Soundcard(s): ',0
  3725.  
  3726. ;sFPUFmt    dc.b    '%s %d.%d MHz  (%ld)',0
  3727. sFPUFmt    dc.b    '%s',0
  3728.  
  3729. sVirtMemFmt    dc.b    ' Max. Virtmem available: %ld K',10,0
  3730.  
  3731. sDBWFmt    dc.b    '  display bandwidth: %dx',0
  3732.  
  3733. sPowerUPFmt0    dc.b    '%2ld PowerUP Processor(s):',0
  3734. sPowerUPFmt1    dc.b    ' PPC %s %ld MHz (rev %d.%d), %ld MHz busclock',0
  3735.  
  3736. sProcInfo060Fmt    dc.b    ' (rev %d)',0
  3737.  
  3738. sSetPatchVerFmt    dc.b    '%d.%d',0
  3739.  
  3740. sOCS    dc.b    'Amiga OCS',0
  3741. sECS    dc.b    'Amiga ECS',0
  3742. sAGA    dc.b    'Amiga AGA',0
  3743. sCyberGfxg    dc.b    'CyberGraphX',0
  3744. sPicasso96g    dc.b    'Picasso96',0
  3745. sProBenchg    dc.b    'ProBench',0
  3746. sEGSg    dc.b    'EGS',0
  3747. sRetinag    dc.b    'Retina',0
  3748. sGraffitig    dc.b    'Graffiti',0
  3749. sTIGAg    dc.b    'TIGA',0
  3750. sAltaisg    dc.b    'Altais',0
  3751.  
  3752. sDenise    dc.b    'OCS Denise 8362',0
  3753. sECSDenise    dc.b    'ECS Denise 8373',0
  3754. sAGALisa    dc.b    'AGA Lisa 4203',0
  3755. sAAALisa    dc.b    'AAA Lisa?',0
  3756.  
  3757. sA0    dc.b    'OCS NTSC Agnus 8361',0            10
  3758. sA1    dc.b    'OCS PAL Agnus 8367',0            00
  3759. sA2    dc.b    'OCS NTSC Fat Agnus 8370',0        10
  3760. sA3    dc.b    'OCS PAL Fat Agnus 8371',0        00
  3761. sA4    dc.b    'ECS NTSC Fatter Agnus 8372a, 1MB',0    30
  3762. sA5    dc.b    'ECS PAL Fatter Agnus 8372a, 1MB',0    20
  3763. sA6    dc.b    'ECS NTSC Super Agnus 8372b, 2MB',0    31
  3764. sA7    dc.b    'ECS PAL Super Agnus 8372b, 2MB',0    21
  3765. sA8    dc.b    'AGA NTSC Alice 8374, thru rev 2',0    32
  3766. sA9    dc.b    'AGA PAL Alice 8374, thru rev 2',0    22
  3767. sAA    dc.b    'AGA NTSC Alice 8374, rev 3-4',0    33
  3768. sAB    dc.b    'AGA PAL Alice 8374, rev 3-4',0        23
  3769. sAxx    dc.b    'ECS Super Agnus 8375, 2MB',0        ??
  3770. sUnknown    dc.b    'Unknown',0
  3771.  
  3772. s68000    dc.b    'MC68000',0
  3773. s68010    dc.b    'MC68010',0
  3774. s68EC020    dc.b    'MC68EC020',0
  3775. s68020    dc.b    'MC68020',0
  3776. s68EC030    dc.b    'MC68EC030',0
  3777. s68030    dc.b    'MC68030',0
  3778. s68EC040    dc.b    'MC68EC040',0
  3779. s68LC040    dc.b    'MC68LC040',0
  3780. s68040    dc.b    'MC68040',0
  3781. s68EC060    dc.b    'MC68EC060',0
  3782. s68LC060    dc.b    'MC68LC060',0
  3783. s68060    dc.b    'MC68060',0
  3784. ;;sMPC603e    dc.b    'MPC603e',0
  3785. ;;sMPC604    dc.b    'MPC604',0
  3786. ;;sMPC620    dc.b    'MPC620',0
  3787.  
  3788. s68881    dc.b    'MC68881',0
  3789. s68882    dc.b    'MC68882',0
  3790. s68040f    dc.b    '68040fpu',0
  3791. s68060f    dc.b    '68060fpu',0
  3792.  
  3793. s68851    dc.b    'MC68851',0
  3794. s68030m    dc.b    '68030mmu',0
  3795. s68040m    dc.b    '68040mmu',0
  3796. s68060m    dc.b    '68060mmu',0
  3797.  
  3798. sPaula    dc.b    'Paula 8364 (rev %d)',0
  3799. sRamsey    dc.b    'Ramsey (rev %d)',0
  3800. sGary    dc.b    'Gary (rev %d)',0
  3801. sGayle    dc.b    'Gayle (rev %d)',0
  3802. sAkiko    dc.b    'Akiko C2P',0
  3803. sSuperIO    dc.b    'SuperIO (rev %d)',0
  3804. sBuster    dc.b    'Buster (rev %d)',0
  3805.  
  3806. sRunningStr    dc.b    'running',0
  3807. sNotActiveStr    dc.b    'not active',0
  3808.  
  3809. sPPC603    dc.b    '603',0
  3810. sPPC604    dc.b    '604',0
  3811. sPPC602    dc.b    '602',0
  3812. sPPC603e    dc.b    '603e',0
  3813. sPPC603p    dc.b    '603p',0
  3814. sPPC604e    dc.b    '604e',0
  3815. sPPCxx    dc.b    '???',0
  3816.  
  3817. sFna
  3818. sMMUna
  3819. sNA
  3820. sGfxEmulna    dc.b    'not available',0
  3821. sNullStr    EQU    *-1
  3822. sClockFound    dc.b    'clock found',0
  3823.  
  3824. sEvalErr    dc.b    'ok, but evaluating code didn''t work! ;)',0
  3825.  
  3826. sUAE    dc.b    ', run by UAE Amiga Emulator',0
  3827. sAmiga1000    dc.b    'is an Amiga 1000',0
  3828. sAmiga500old    dc.b    'is an old Amiga 500',0
  3829. sAmiga500    dc.b    'probably is an Amiga 500',0
  3830. sAmiga500e    dc.b    'is an expanded Amiga 500',0
  3831. sAmiga500Plus    dc.b    'probably is an Amiga 500+',0
  3832. sAmiga500Pluse    dc.b    'is an expanded Amiga 500+',0
  3833. sAmiga600    dc.b    'is an Amiga 600',0
  3834. sAmiga1200    dc.b    'is an Amiga 1200',0
  3835. sAmiga1400    dc.b    'is an Amiga 1400',0
  3836. sAmiga2000    dc.b    'probably is an Amiga 2000',0
  3837. sAmiga2000e    dc.b    'is an expanded Amiga 2000',0
  3838. sAmiga2000Plus    dc.b    'probably is an Amiga 2000+',0
  3839. sAmiga2000Pluse    dc.b    'is an expanded Amiga 2000+',0
  3840. sAmiga2500    dc.b    'is an Amiga 2500',0
  3841. sAmiga3000    dc.b    'is an Amiga 3000',0
  3842. sAmiga3000UX    dc.b    'is an Amiga 3000UX',0
  3843. sAmiga3000T    dc.b    'is an Amiga 3000 Tower',0
  3844. sAmiga4000    dc.b    'is an Amiga 4000',0
  3845. sAmiga4000T    dc.b    'probably is an Amiga 4000 Tower',0
  3846. sCD32    dc.b    'is an Amiga CD³²',0
  3847. sCDTV    dc.b    'is an Amiga CDTV',0
  3848. ;XsWalker    dc.b    'is Amiga Techologies'' Walker',0
  3849. sDraCo    dc.b    'is MacroSystems'' DraCo (Amiga-clone)',0
  3850. sAmigaAAA    dc.b    'probably is a new AAA Amiga (portable? PowerAmiga?)',0
  3851. sDefault    dc.b    'is some Amiga or compatible',0
  3852.  
  3853.  
  3854. GFXBRD    MACRO
  3855.     dc.l    (($\1)<<16)!\2,\3
  3856.     ENDM
  3857.  
  3858. ;    $140C    2    'US Interface Ltd. Magic graphics',0
  3859. ;    $140C    130    'US Interface Ltd. Magic graphics (Prototype)',0
  3860.  
  3861.     CNOP    0,4
  3862. GfxBoardTable
  3863.     GFXBRD    07E1,32,sIV24
  3864.     GFXBRD    06E1,32,sIV24
  3865.     GFXBRD    0891,2,sEGS
  3866.     GFXBRD    0838,0,sIF24        NTSC
  3867.     GFXBRD    0838,1,sIF24        PAL
  3868.     GFXBRD    0851,1,sResolver
  3869.     GFXBRD    0851,2,sVivid24
  3870.     GFXBRD    086A,3,sVoyager
  3871.     GFXBRD    086A,2,sBlackbox
  3872.     GFXBRD    086A,1,sHorizon
  3873.     GFXBRD    085E,1,sGDA
  3874.     GFXBRD    0406,0,sA2410
  3875.     GFXBRD    03EC,245,sA2410kronos
  3876.     GFXBRD    0845,2,sVisiona
  3877.     GFXBRD    0845,4,sMerlin
  3878.     GFXBRD    2140,34,sCyberVision
  3879.     GFXBRD    07E1,68,sRembrandt
  3880.     GFXBRD    0872,2,sDomino
  3881.     GFXBRD    0893,5,sPiccolo        (actually Piccolo Memory)
  3882.     GFXBRD    0893,11,sPiccoloSD64
  3883.     GFXBRD    0877,12,sPicassoII
  3884.     GFXBRD    0877,13,sPicassoII
  3885.     GFXBRD    4754,6,sRetinaZ2
  3886.     GFXBRD    4754,16,sRetinaZ3
  3887.     GFXBRD    0861,33,sRainbowIII
  3888.     GFXBRD    0877,24,sPicassoIV
  3889.     GFXBRD    2140,50,sCyberVision3D
  3890.     GFXBRD    2140,67,sCyberVision3D
  3891.     GFXBRD    4754,19,sAltais
  3892.     GFXBRD    041D,20,s1600GX
  3893.  
  3894. ;    GFXBRD    2140,13,sIV24        db
  3895. ;    GFXBRD    2140,13,sEGS
  3896. ;    GFXBRD    2140,13,sResolver    Testing 1.2.3...
  3897. ;    GFXBRD    2140,13,sA2410
  3898.     dc.l    0
  3899.  
  3900. sA2410    dc.b    'Lowell A2410',0
  3901. sA2410kronos    dc.b    'Kronos/C Ltd A2410',0
  3902. sIV24    dc.b    'Impact Vision 24',0
  3903. sEGS    dc.b    'EGS Spectrum',0
  3904. sIF24    dc.b    'FireCracker 24',0
  3905. sResolver    dc.b    'Resolver',0
  3906. sVivid24    dc.b    'Vivid 24',0
  3907. sGDA    dc.b    'GDA-1',0
  3908. sHorizon    dc.b    'Horizon',0
  3909. sBlackbox    dc.b    'Blackbox',0
  3910. sVoyager    dc.b    'Voyager',0
  3911. sVisiona    dc.b    'Visiona',0
  3912. sMerlin    dc.b    'Merlin',0
  3913. sCyberVision    dc.b    'CyberVision 64',0
  3914. sRembrandt    dc.b    'Rembrandt',0
  3915. sDomino    dc.b    'Domino',0
  3916. sPiccolo    dc.b    'Piccolo',0
  3917. sPiccoloSD64    dc.b    'PiccoloSD-64',0
  3918. sPicassoII    dc.b    'Picasso II',0
  3919. sRetinaZ2    dc.b    'Retina Z2',0
  3920. sRetinaZ3    dc.b    'Retina Z3',0
  3921. sRainbowIII    dc.b    'Rainbow III',0
  3922. sAltais    dc.b    'Altais Card',0
  3923. s1600GX    dc.b    '1600-GX',0
  3924. sCyberVision3D    dc.b    'CyberVision 64/3D',0
  3925. sPicassoIV    dc.b    'Picasso IV',0
  3926.     CNOP    0,4
  3927.  
  3928.  
  3929. SNDCRD    MACRO
  3930.     dc.l    (($\1)<<16)!\2,\3
  3931.     ENDM
  3932.  
  3933.     CNOP    0,4
  3934. SndCardTable
  3935.     SNDCRD    0840,191,sWavetools
  3936.     SNDCRD    38A5,0,sDelfina
  3937.     SNDCRD    4231,1,sPrelude
  3938.     SNDCRD    4754,3,sMaestro
  3939.     SNDCRD    4754,5,sMaestroPro
  3940.     SNDCRD    4754,12,sToccata
  3941.     SNDCRD    4754,13,sToccataPro
  3942.     SNDCRD    38A5,1,sDelfinaLITE
  3943.  
  3944. ;    SNDCRD    2140,13,sDelfina    db
  3945. ;    SNDCRD    2140,13,sMaestroPro
  3946.     dc.l    0
  3947.  
  3948. sWavetools    dc.b    'Wavetools',0
  3949. sDelfina    dc.b    'Delfina DSP',0
  3950. sPrelude    dc.b    'Prelude',0
  3951. sMaestro    dc.b    'Maestro',0
  3952. sMaestroPro    dc.b    'MaestroPro',0
  3953. sToccata    dc.b    'Toccata',0
  3954. sToccataPro    dc.b    'ToccataPro',0
  3955. sDelfinaLITE    dc.b    'Delfina LITE',0
  3956.  
  3957.     CNOP    0,4
  3958. ExecBase00    dc.l    'EXEC'
  3959.  
  3960.  
  3961.     CNOP    0,4
  3962. ;;    SECTION    BSS,BSS
  3963.  
  3964. ;;ExecBase01    ds.l    1
  3965.  
  3966. Params
  3967. CPU    ds.l    1
  3968. MHz    ds.l    1
  3969. procinfo_ptr    ds.l    1
  3970. ;Multiplier    ds.w    1
  3971. ;CmpCPU_ptr    ds.l    1
  3972. ;CmpCPUMHz    ds.w    1
  3973. ;WAIndex    ds.l    1
  3974. PowerUP_ptr    ds.l    1
  3975. FPU_ptr    ds.l    1
  3976. MMU    ds.l    1
  3977. MMUStatus    ds.l    1
  3978. GfxChip    ds.l    1
  3979. GfxChipRev_ptr    ds.l    1
  3980. AnimChip    ds.l    1
  3981. CustomChips    ds.l    1
  3982. GfxLibEmul_ptr    ds.l    1
  3983. BandWidth_ptr    ds.l    1
  3984. GfxBoardI    ds.l    1
  3985. GfxBoard    ds.l    1
  3986. C2P    ds.l    1
  3987. SndCardI    ds.l    1
  3988. SndCard    ds.l    1
  3989. HWClock_ptr    ds.l    1
  3990. ChipMemd    ds.l    1
  3991. FastMem    ds.l    1
  3992. VirtMem_ptr    ds.l    1
  3993. RomVer    ds.l    1
  3994. RomVerS    ds.l    1
  3995. ReKickROM_ptr    ds.l    1
  3996. WBVer    ds.l    1
  3997. WBVerS    ds.l    1
  3998. SetPatchVerPtr    ds.l    1
  3999. ExpBoards_ptr    ds.l    1
  4000. MachineGuess    ds.l    1
  4001. AfterMG_ptr    ds.l    1
  4002.  
  4003. CPUCompareTime    ds.l    1
  4004. FPUCompareTime    ds.l    1
  4005. CPUID    ds.l    1
  4006. EC    ds.l    1
  4007. _EC    ds.l    1
  4008. GfxLibEmul    ds.l    1
  4009. CRomVer    ds.l    1            \
  4010. CRomVerS    ds.l    1            /
  4011. CRomChkSum    ds.l    1
  4012. RomChkSum    ds.l    1
  4013. ;RamseyGaryRev
  4014. RamseyRev    ds.w    1
  4015. GaryRev    ds.w    1
  4016. GfxChipRev    ds.w    1
  4017.     ds.w    1
  4018. GfxChipID    ds.l    1
  4019. AnimChipID    ds.l    1
  4020. FPUID    ds.l    1
  4021. CardSlotID    ds.l    1
  4022. DraCoID    ds.l    1
  4023. PowerUPID    ds.l    1
  4024. UAEID    ds.l    1
  4025. GayleRev    ds.w    1
  4026. PaulaRev    ds.w    1
  4027. AGAGayleID    ds.l    1
  4028. A690ID    ds.l    1
  4029. CDTVID    ds.l    1
  4030. ATIDEID    ds.l    1
  4031. C2PID
  4032. AkikoID    ds.l    1
  4033. CD32NVRAMID    ds.l    1
  4034. UNIXID    ds.l    1
  4035. A500EID    ds.l    1
  4036. A2000EID    ds.l    1
  4037. A3000ID    ds.l    1
  4038. A4000ID    ds.l    1
  4039. A4091ID    ds.l    1
  4040. Phase5ID    ds.l    1
  4041. A4000TID    ds.l    1
  4042. A2500ID    ds.l    1
  4043. _100kHz    ds.l    1
  4044. HWClockID    ds.l    1
  4045. VirtMem    ds.l    1
  4046. AddrBits    ds.l    1
  4047. BandWidth    ds.w    1
  4048.     ds.w    1    Align
  4049.  
  4050. _ThisTask    ds.l    1
  4051. _Args    ds.l    1
  4052. _DosBase    ds.l    1
  4053. _ExpBase    ds.l    1
  4054. _wasDSACK    ds.l    1
  4055. _CiaInterrupt    ds.l    1
  4056. NewKick    ds.l    1
  4057. WBMode    ds.l    1
  4058. OutputFH    ds.l    1
  4059. EvalSpSave    ds.l    1
  4060. ChipMem    ds.l    1
  4061. ; disabled this x thing:
  4062. Multiplier    ds.w    1
  4063. CmpCPU_ptr    ds.l    1
  4064. CmpCPUMHz    ds.w    1
  4065. WAIndex    ds.l    1
  4066.  
  4067. pf_Data    ds.l    1    dosbase
  4068.     ds.l    1    cnt
  4069.     ds.b    256    text-buffer
  4070.  
  4071. FPUBuffer    ds.b    32
  4072. GfxBoardBuffer    ds.b    256
  4073. SndCardBuffer    ds.b    256
  4074. sVirtMemBuf    ds.b    80
  4075. sROMBuf    ds.b    80
  4076. ChipsBuffer    ds.b    80+2
  4077. GChipRevBuffer    ds.b    20
  4078. DBWBuffer    ds.b    32
  4079. ExpBoardsBuffer    ds.b    (10+10+6+4+48+48)*20
  4080. sPowerUPBuf    ds.b    80*8
  4081. sSetPatchBuf    ds.b    16
  4082. sPI060Buffer    ds.b    32
  4083.  
  4084.  
  4085.     SECTION    CODE_C,CODE_C        Virtmem sensitive parts:
  4086.  
  4087. ExecBase02    dc.l    'EXEC'
  4088.  
  4089.  
  4090.     include    "utility/utility_lib.i"
  4091.     IFND    _LVOReadEClock
  4092. _LVOReadEClock    EQU    -$3C
  4093.     ENDC
  4094.     CNOP    0,4
  4095. ;  IN: a0=init_routine, a1=time_routine, a2=cleanup_routine
  4096. ; OUT: d0=microseconds time_routine took to execute, -1 for error
  4097. ;NOTE: init_time_routine may change cache settings, loadview(0) etc.
  4098. ;      do NOT change a5!
  4099. TimeRoutine
  4100.     STRUCTURE mytimerstuff,0
  4101.     APTR    mts_execbase
  4102.     APTR    mts_timerbase
  4103.     APTR    mts_utilitybase
  4104.     STRUCT    mts_beg_eclockval,EV_SIZE
  4105.     STRUCT    mts_end_eclockval,EV_SIZE
  4106.     ;
  4107.     APTR    mts_init_routine
  4108.     APTR    mts_time_routine
  4109.     APTR    mts_cleanup_routine
  4110.     ULONG    mts_eclockfreq
  4111.     ;
  4112.     APTR    mts_ciabbase
  4113.     ULONG    mts_timerbit
  4114.     ULONG    mts_timermask
  4115.     UWORD    mts_oldAbleICRmask
  4116.     UWORD    mts_oldSetICRmask
  4117.     APTR    mts_ciabcrx
  4118.     APTR    mts_ciabtxlo
  4119.     STRUCT    mts_IS,IS_SIZE
  4120.     ALIGNLONG
  4121.     STRUCT    mts_icode,8
  4122.     LABEL    mts_fullrounds
  4123.     ULONG    mts_idata
  4124.     ULONG    mts_idata_add
  4125.     LABEL    mts_SIZEOF
  4126.  
  4127.  
  4128.     movem.l    d1-a6,-(sp)
  4129.     moveq    #-1,d7
  4130.     move.l    (4).w,a6
  4131.     cmp.w    #36,(LIB_VERSION,a6)
  4132.     shs    d6
  4133.  
  4134.     move.l    a0,d2
  4135.     move.l    a1,d3
  4136.     move.l    a2,d4
  4137.     move.l    #mts_SIZEOF,d0
  4138.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    No virtmem please!
  4139.     call    AllocMem
  4140.     tst.l    d0
  4141.     beq    .exit
  4142.     move.l    d0,a5
  4143.     move.l    a6,(mts_execbase,a5)
  4144.     move.l    d2,(mts_init_routine,a5)
  4145.     move.l    d3,(mts_time_routine,a5)
  4146.     move.l    d4,(mts_cleanup_routine,a5)
  4147.  
  4148.     tst.b    d6
  4149.     beq.b    .nov36a
  4150.     lea    (DeviceList,a6),a0
  4151.     lea    (.timername,pc),a1
  4152.     call    Forbid
  4153.     call    FindName
  4154.     call    Permit
  4155.     move.l    d0,(mts_timerbase,a5)
  4156.     beq    .free
  4157.     bra    .got_timerbase
  4158. .nov36a
  4159.     move.l    #709379,(mts_eclockfreq,a5)
  4160.     cmp.b    #50,(PowerSupplyFrequency,a6)
  4161.     beq.b    .was_pal
  4162.     move.l    #715909,(mts_eclockfreq,a5)
  4163.     cmp.b    #60,(PowerSupplyFrequency,a6)
  4164.     bne    .free
  4165. .was_pal
  4166.     lea    (.ciabname,pc),a1
  4167.     call    OpenResource
  4168.     move.l    d0,(mts_ciabbase,a5)
  4169.     beq    .free
  4170.  
  4171.     lea    (mts_IS+LN_TYPE,a5),a1
  4172.     move.w    #NT_INTERRUPT<<8+127,(a1)+
  4173.     lea    (.ciaintname,pc),a0
  4174.     move.l    a0,(a1)+
  4175.     lea    (mts_idata,a5),a0
  4176.     move.l    a0,(a1)+
  4177.     lea    (mts_icode,a5),a0
  4178.     move.l    a0,(a1)+
  4179.     move.l    #$2029<<16!mts_idata_add-mts_idata,(a0)+ ;move.l (mts_idata_add-mts_idata,a1),d0
  4180.     move.l    #$D1914E75,(a0)                 ;add.l d0,(a1); rts
  4181.     move.l    #$10000,(mts_idata_add,a5)
  4182.     bsr    .cacheclear
  4183.  
  4184.     call    Disable
  4185.     move.l    (mts_ciabbase,a5),a6
  4186.     moveq    #1,d2
  4187. .allocloop    move.l    d2,d0
  4188.      lea    (mts_IS,a5),a1
  4189.     call    AddICRVector
  4190.     tst.l    d0
  4191.     beq.b    .ciaok
  4192.     dbf    d2,.allocloop
  4193.     bra.b    .no_timer
  4194. .ciaok    move.w    d2,d0
  4195.     move.l    d2,(mts_timerbit,a5)
  4196.     moveq    #1,d0
  4197.     lsl.l    d2,d0
  4198.     move.l    d0,(mts_timermask,a5)
  4199.     call    SetICR            Clear timer interrupt
  4200.     or.w    #$80,d0
  4201.     move.w    d0,(mts_oldSetICRmask,a5)
  4202.     move.l    (mts_timermask,a5),d0    Disable timer interrupt
  4203.     call    AbleICR
  4204.     or.w    #$80,d0
  4205.     move.w    d0,(mts_oldAbleICRmask,a5)
  4206. .no_timer    move.l    (mts_execbase,a5),a6
  4207.     call    Enable
  4208.     tst.w    d2
  4209.     bmi    .free
  4210.     move.l    (mts_timerbit,a5),d0
  4211.     lsl.l    #8,d0
  4212.     lea    CIAB+ciacra,a0
  4213.     add.w    d0,a0
  4214.     move.l    a0,(mts_ciabcrx,a5)
  4215.     add.w    d0,d0
  4216.     lea    CIAB+ciatalo,a0
  4217.     add.w    d0,a0
  4218.     move.l    a0,(mts_ciabtxlo,a5)
  4219.     move.l    (mts_ciabcrx,a5),a0    Stop timer, set continuos mode, count 02 pulses
  4220.     clr.b    (a0)
  4221.     move.l    (mts_ciabtxlo,a5),a0    Set timeout (counter)
  4222.     st    (a0)
  4223.     st    ($100,a0)
  4224.     move.l    (mts_ciabbase,a5),a6
  4225.     move.l    (mts_timermask,a5),d0
  4226.     or.w    #$80,d0            Enable timer interrupt
  4227.     call    AbleICR
  4228.  
  4229.     move.l    (mts_init_routine,a5),d0
  4230.     beq.b    .noinita
  4231.     move.l    d0,a0
  4232.     jsr    (a0)
  4233. .noinita    movem.l    d0-d1/a0-a1,-(sp)
  4234.  
  4235.     move.l    (mts_ciabcrx,a5),a0    set OUTMODE(?), RUNODE=cont, LOAD counter, START
  4236.     move.b    #%00010101,(a0)
  4237.  
  4238.     movem.l    (sp)+,d0-d1/a0-a1
  4239.     move.l    (mts_time_routine,a5),a0
  4240.     jsr    (a0)
  4241.  
  4242.     move.l    (mts_ciabcrx,a5),a0    Stop timer.
  4243.     clr.b    (a0)
  4244.  
  4245.     move.l    (mts_cleanup_routine,a5),d0
  4246.     beq.b    .nocleana
  4247.     move.l    d0,a0
  4248.     jsr    (a0)
  4249. .nocleana
  4250.     ; stopped
  4251.     moveq    #0,d1
  4252.     move.l    (mts_ciabtxlo,a5),a0    Get timer counter
  4253.     move.l    #$FFFF,d0
  4254.     move.b    ($100,a0),d1
  4255.     lsl.l    #8,d1
  4256.     move.b    (a0),d1
  4257.     sub.l    d1,d0            d0=count
  4258.     add.l    (mts_fullrounds,a5),d0    Add full timer rounds (rounds*$10000)
  4259.     move.l    d0,d2
  4260.  
  4261.     move.l    (mts_execbase,a5),a6
  4262.     call    Disable
  4263.     move.l    (mts_ciabbase,a5),a6
  4264.     move.l    (mts_timermask,a5),d0    Clear timer interrupt
  4265.     call    SetICR
  4266.     move.l    (mts_timermask,a5),d0    Disable timer interrupt
  4267.     call    AbleICR
  4268.     move.w    (mts_oldSetICRmask,a5),d0
  4269.     call    SetICR            Set orig timer interrupt
  4270.     move.w    (mts_oldAbleICRmask,a5),d0
  4271.     call    AbleICR            Enable orig interrupt
  4272.     lea    (mts_IS,a5),a1
  4273.     call    RemICRVector
  4274.     move.l    (mts_execbase,a5),a6
  4275.     call    Enable
  4276.  
  4277.     ;d2=EV_LO
  4278.  
  4279. .free    move.l    (mts_execbase,a5),a6
  4280.     move.l    a5,a1
  4281.     move.l    #mts_SIZEOF,d0
  4282.     call    FreeMem
  4283.  
  4284. .exit    move.l    d7,d0
  4285.     movem.l    (sp)+,d1-a6
  4286.     rts
  4287.  
  4288.  
  4289. .cacheclear    move.w    (AttnFlags,a6),d0
  4290.     btst    #AFB_68020,d0
  4291.     beq.b    .cc_nocache
  4292.     move.l    a5,a0
  4293.     lea    (.cc_cachec,pc),a5
  4294.     jmp    (_LVOSupervisor,a6)
  4295. .cc_nocache    rts
  4296. .cc_cachec    move.l    a0,a5
  4297.     btst    #AFB_68040,d0
  4298.     bne.b    .cc_040p
  4299.     movec    cacr,d0
  4300.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  4301.     movec    d0,cacr
  4302.     rte
  4303. .cc_040p    dc.w    $F478        ; CPUSHA BC    flush the data into memory
  4304.     nop
  4305.     rte
  4306.  
  4307.  
  4308. .got_timerbase    lea    (.utilityname,pc),a1
  4309.     moveq    #36,d0
  4310.     call    OpenLibrary
  4311.     move.l    d0,(mts_utilitybase,a5)
  4312.     beq    .free
  4313.  
  4314.     move.l    (mts_init_routine,a5),d0
  4315.     beq.b    .noinitb
  4316.     move.l    d0,a0
  4317.     jsr    (a0)
  4318. .noinitb    movem.l    d0-d1/a0-a1/a6,-(sp)
  4319.  
  4320.     move.l    (mts_timerbase,a5),a6
  4321.     lea    (mts_beg_eclockval,a5),a0
  4322.     call    ReadEClock
  4323.  
  4324.     movem.l    (sp)+,d0-d1/a0-a1/a6
  4325.     move.l    (mts_time_routine,a5),a0
  4326.     jsr    (a0)
  4327.  
  4328.     move.l    (mts_timerbase,a5),a6
  4329.     lea    (mts_end_eclockval,a5),a0
  4330.     call    ReadEClock
  4331.     move.l    d0,(mts_eclockfreq,a5)
  4332.  
  4333.     move.l    (mts_cleanup_routine,a5),d0
  4334.     beq.b    .nocleanb
  4335.     move.l    d0,a0
  4336.     jsr    (a0)
  4337. .nocleanb
  4338.     move.l    (mts_end_eclockval+EV_HI,a5),d0
  4339.     cmp.l    (mts_beg_eclockval+EV_HI,a5),d0
  4340.     bne.b    .closeu
  4341.  
  4342.     ;efreqmul=2000
  4343.     ;evalmul=1000000/efreqmul
  4344.     ;micros=eval*evalmul/efreq*efreqmul
  4345.  
  4346. efreqmul    EQU    2000
  4347. evalmul    EQU    1000000/efreqmul
  4348.  
  4349.     move.l    (mts_utilitybase,a5),a6
  4350.  
  4351.     move.l    (mts_eclockfreq,a5),d0
  4352.     move.l    #efreqmul,d1
  4353.     call    UMult32
  4354.     move.l    d0,d2            efreq*efreqmul
  4355.     beq.b    .closeu
  4356.  
  4357.     move.l    (mts_end_eclockval+EV_LO,a5),d0
  4358.     sub.l    (mts_beg_eclockval+EV_LO,a5),d0
  4359.     IFGT    0
  4360.     move.l    #evalmul,d1
  4361.     call    UMult32            eval*evalmul
  4362.  
  4363.     move.l    d2,d1
  4364.     call    UDivMod32
  4365.     ;d0=micros=eval*evalmul/efreq*efreqmul
  4366.     ENDC
  4367.     move.l    d0,d7
  4368.  
  4369. .closeu    move.l    (mts_execbase,a5),a6
  4370.     move.l    (mts_utilitybase,a5),a1
  4371.     call    CloseLibrary
  4372.     bra    .free
  4373.  
  4374.  
  4375. .timername    dc.b    'timer.device',0
  4376. .utilityname    dc.b    'utility.library',0
  4377. .ciabname    dc.b    'ciab.resource',0
  4378. .ciaintname    dc.b    'TimeRoutine cia-b interrupt',0
  4379.     CNOP    0,4
  4380.  
  4381.  
  4382. ; Test 68030, 68040 and 68882 WITHOUT system (for KS1.x use)
  4383. ;  IN: d2=attnflags, a6=execbase
  4384. ; OUT: d0=updated attnflags
  4385. Test030_040_882    move.l    a5,-(sp)
  4386.     lea    (.sv,pc),a5
  4387.     call    Supervisor
  4388.     move.l    (sp)+,a5
  4389.     rts
  4390.  
  4391. .sv    moveq    #0,d0
  4392.     btst    #AFB_68020,d2
  4393.     beq.b    .not68020
  4394.     movec    cacr,d1
  4395.     move.l    d1,-(sp)
  4396.     or.w    #CACRF_WriteAllocate,d1
  4397.     movec    d1,cacr
  4398.     movec    cacr,d1
  4399.     btst    #CACRB_WriteAllocate,d1
  4400.     beq.b    .not68030
  4401.     bset    #AFB_68030,d0
  4402. .not68030    move.l    (sp)+,d1
  4403.     movec    d1,cacr
  4404.  
  4405.     movec    cacr,d1
  4406.     move.l    d1,-(sp)
  4407.     or.w    #CACRF_EnableI!CACRF_ClearI!CACRF_ClearD!CACRF_WriteAllocate,d1
  4408.     movec    d1,cacr
  4409.     movec    cacr,d1
  4410.     btst    #CACRB_EnableI,d1
  4411.     bne.b    .not68040
  4412.     or.b    #AFF_68040!AFF_68030,d0
  4413. .not68040    move.l    (sp)+,d1
  4414.     or.w    #CACRF_ClearI!CACRF_ClearD!CACRF_WriteAllocate,d1
  4415.     movec    d1,cacr
  4416. .not68020
  4417.     btst    #AFB_68881,d2
  4418.     beq.b    .no882
  4419.  
  4420.     moveq    #0,d1
  4421.     dc.w    $F201,$9000
  4422.     dc.w    $F201,$B000
  4423.  
  4424.     dc.w    $F327
  4425.     dc.w    $0C2F,$0018,$0001        cmp.b    #$18,(1,sp)
  4426.     beq.b    .flushstack
  4427.     bset    #AFB_68882,d0
  4428. .flushstack    dc.w    $F35F
  4429. .no882    nop                sync pipelines
  4430.     rte
  4431.  
  4432.  
  4433.  
  4434.  
  4435.     IFGT    0
  4436.  
  4437.  >> Information taken from '68060 Upgrade Software Guide' <<
  4438.  
  4439. 2) Inststructions supported by the 68040 but not by the 68060 directly that
  4440.    can hurt performance:
  4441.  
  4442.  o divx.l (64bit divide)
  4443.  o mulx.l (64bit multiply)
  4444.  o fdbcc
  4445.  o fscc
  4446.  o movep
  4447.  o There are other instructions that are not supported or have to
  4448.    be emulated but these aren't relevant for user applications.
  4449.     ENDC
  4450.  
  4451. Test060    move.l    a5,-(sp)
  4452.     lea    (.test060,pc),a5
  4453.     call    Disable            No others playing around, please.
  4454.     call    Supervisor        Ramsey revision:
  4455.     call    Enable
  4456.     move.l    (sp)+,a5
  4457.     rts
  4458.  
  4459. .test060    movec    vbr,a0            Hijack illegal instr. trap
  4460.     move.l    ($10,a0),-(sp)
  4461.     move.l    ($2C,a0),-(sp)
  4462.     move.l    a0,-(sp)
  4463.     lea    (.illegal,pc),a1
  4464.     move.l    a1,($10,a0)
  4465.     move.l    a1,($2C,a0)
  4466.     bsr    _flush040
  4467.  
  4468.     moveq    #0,d0
  4469.  
  4470.     dc.w    $4E7A,$0008        movec    BUSCR,d0
  4471.     dc.w    $4E7A,$0808        movec    PCR,d0
  4472.  
  4473.     nop
  4474.     nop
  4475.     moveq    #1,d0
  4476. .exit_illegal
  4477.     move.l    (sp)+,a0        Restore illegal instr. trap
  4478.     move.l    (sp)+,($2C,a0)
  4479.     move.l    (sp)+,($10,a0)
  4480.     move.l    d0,-(sp)
  4481.     bsr    _flush040
  4482.     move.l    (sp)+,d0
  4483.     beq.b    .no060
  4484.  
  4485.     or.w    #AFF_68060,d2
  4486. .no060    nop
  4487.     rte
  4488.  
  4489.     CNOP    0,4
  4490. .illegal    lea    (.exit_illegal,pc),a0
  4491.     move.l    a0,(2,sp)
  4492.     nop                sync pipelines
  4493.     rte
  4494.  
  4495.  
  4496.  
  4497. CacheClearU    moveq    #0,d1
  4498. CacheControl    movem.l    d1-d2/a0/a1/a5/a6,-(sp)
  4499.     move.l    (4).w,a6        Use (4).w!!!
  4500.     or.w    #CACRF_ClearI!CACRF_ClearD!CACRF_WriteAllocate,d0
  4501.     or.w    #CACRF_ClearI!CACRF_ClearD!CACRF_WriteAllocate,d1
  4502.     cmp.w    #37,(LIB_VERSION,a6)
  4503.     blo.b    .oldkick
  4504.     call    CacheControl
  4505.     bra.b    .xit
  4506.  
  4507. .oldkick    btst    #AFB_68020,_AttnFlags+1
  4508.     beq.b    .xit
  4509.     lea    (.sv,pc),a5
  4510.     call    Supervisor
  4511. .xit    movem.l    (sp)+,d1-d2/a0/a1/a5/a6
  4512.     rts
  4513.  
  4514. .sv    movec    cacr,d2
  4515.     move.l    d2,-(sp)
  4516.     and.l    d1,d0
  4517.     not.l    d1
  4518.     and.l    d1,d2
  4519.     or.l    d2,d0
  4520.     movec    d0,cacr
  4521.     move.l    (sp)+,d0
  4522.     nop                sync pipelines
  4523.     rte
  4524.  
  4525.  
  4526. ;  IN: (extended attnflags field, MMU routines available)
  4527. ; OUT: d0=24 or 32
  4528. GetAddressBits    movem.l    d1-a6,-(sp)
  4529.     moveq    #32,d7
  4530.  
  4531.     tst.l    DraCoID            DraCo has 32bit 68060!
  4532.     bne.b    .xit
  4533.  
  4534.     lea    (_getaddrbits,pc),a0
  4535.     moveq    #1,d0
  4536.     bsr    RunNoMMU
  4537. .xit    move.l    d7,d0
  4538.     movem.l    (sp)+,d1-a6
  4539.     rts
  4540.  
  4541. _getvbr    sub.l    a0,a0
  4542.     btst    #AFB_68010,_AttnFlags+1
  4543.     beq.b    .novbr
  4544.     movec    vbr,a0
  4545. .novbr    rts
  4546.  
  4547. _getaddrbits    bsr.b    _getvbr
  4548.     move.l    ($08,a0),-(sp)        Save Access Fault vector
  4549.     move.l    a0,-(sp)        Save VBR
  4550.     lea    (.busfailure,pc),a1    Set new Access Fault vector:
  4551.     move.l    a1,($08,a0)
  4552.  
  4553.     lea    AddrChipData,a0        16 byte chip buffer
  4554.     move.l    #$BADCAFFE,d1
  4555.     move.l    #$DEADBABE,d2
  4556.     move.l    #'lOVE',d3
  4557.     move.l    #'8biT',d4
  4558.  
  4559.     move.w    #256-1-1,d5
  4560.     movem.l    d1-d4,(a0)
  4561.     move.l    a0,a1
  4562. .loop    add.l    #$1000000,a1
  4563.  
  4564.     moveq    #4-1,d0
  4565.     move.l    a0,a2
  4566.     move.l    a1,a3
  4567. .compare    cmpm.l    (a2)+,(a3)+
  4568.     dbne    d0,.compare
  4569.     tst.w    d0
  4570.     dbpl    d5,.loop
  4571.  
  4572.     tst.w    d5
  4573.     bpl.b    .exit            Is 32bit
  4574.  
  4575.     exg    d1,d4
  4576.     exg    d2,d3
  4577.     movem.l    d1-d4,(a0)
  4578.     movem.l    (a1),d5-d6/a4-a5
  4579.     movem.l    d1-d4,(a1)
  4580.  
  4581.     moveq    #4-1,d0
  4582.     move.l    a0,a2
  4583.     move.l    a1,a3
  4584. .compare2    cmpm.l    (a2)+,(a3)+
  4585.     dbne    d0,.compare2
  4586.  
  4587.     movem.l    d5-d6/a4-a5,(a1)
  4588.  
  4589.     tst.w    d0
  4590.     bmi.b    .exit            Isn't 24bit
  4591.  
  4592.     moveq    #24,d7
  4593.  
  4594. .exit
  4595. .busfproceed    move.l    (sp)+,a0        Restore VBR
  4596.     move.l    (sp)+,($08,a0)        Restore Access Fault vector
  4597. .xit    move.l    d7,d0
  4598.     rts
  4599.  
  4600.     CNOP    0,4
  4601. .busfailure    bclr    #0,(10,sp)
  4602.     beq.b    .bf_exit
  4603.     moveq    #32,d7            If CPU can generate bus failure then it's 32bit
  4604.     lea    (.busfproceed,pc),a0
  4605.     move.l    a0,(2,sp)
  4606. .bf_exit    nop                sync pipelines
  4607.     rte
  4608.  
  4609.  
  4610.     CNOP    0,4
  4611. GetVbr    move.l    a5,-(sp)
  4612.     sub.l    a0,a0
  4613.     btst    #AFB_68010,_AttnFlags+1
  4614.     beq.b    .novbr
  4615.     lea    (.getvbr,pc),a5
  4616.     call    Supervisor
  4617. .novbr    move.l    (sp)+,a5
  4618.     rts
  4619. .getvbr    movec    vbr,a0
  4620.     nop                sync pipelines
  4621.     rte
  4622.  
  4623.  
  4624.     CNOP    0,4
  4625. ChipTiming2    bsr    Disable
  4626.  
  4627.     IFGT    0
  4628.     tst.l    NoHW
  4629.     bne.b    .nohw1
  4630.     move.w    (dmaconr,a4),d0
  4631.     and.w    #$000F,d0        only audio dma please...
  4632.     or.w    #$8000,d0        set
  4633.     move.w    #$000F,(dmacon,a4)    Disable audio dma
  4634.     move.l    d0,-(sp)
  4635. .nohw1
  4636.     ENDC
  4637.  
  4638.     move.l    #CACRF_EnableI,d0    Disable all but inst cache for test
  4639.     move.l    #~CACRF_WriteAllocate,d1 WAS: -1
  4640.     bsr    CacheControl
  4641.     move.l    d0,-(sp)        Save prev cache state
  4642.  
  4643.     jsr    turnon060caches
  4644.  
  4645.     move.l    TimerBit,d0
  4646.     lsl.l    #8,d0
  4647.     lea    CIAB+ciacra,a2
  4648.     add.w    d0,a2
  4649.     add.w    d0,d0
  4650.     lea    CIAB+ciatalo,a3
  4651.     add.w    d0,a3
  4652.  
  4653.     move.l    CiabResource,a6
  4654.     move.l    TimerMask,d0        Clear timer interrupts
  4655.     call    SetICR
  4656.     moveq    #$7F,d0            Disable all timer interrupts
  4657.     call    AbleICR
  4658.     move.l    d0,-(sp)
  4659.     clr.b    (a2)            Stop timer, set continuos mode, count 02 pulses
  4660.     st    (a3)            Set timeout
  4661.     st    ($100,a3)
  4662.     move.l    TimerMask,d0
  4663.     or.w    #1<<7,d0        Enable timer interrupt
  4664.     call    AbleICR
  4665.  
  4666.     move.l    (ExecBase02,pc),a6
  4667.     bsr    ChipTiming
  4668.     move.l    d0,d7
  4669.  
  4670.     move.l    CiabResource,a6
  4671.     moveq    #$7F,d0            Disable all timer interrupts
  4672.     call    AbleICR
  4673.     move.l    (sp)+,d0        Restore old timer interrupts
  4674.     or.w    #1<<7,d0
  4675.     call    AbleICR
  4676.  
  4677.     jsr    restore060caches
  4678.  
  4679.     move.l    (ExecBase02,pc),a6    Restore cache state
  4680.     move.l    (sp)+,d0
  4681.     moveq    #-1,d1
  4682.     bsr    CacheControl
  4683.  
  4684.     IFGT    0
  4685.     tst.l    NoHW
  4686.     bne.b    .nohw2
  4687.     move.l    (sp)+,d0
  4688.     move.w    d0,(dmacon,a4)        Enable audio dma
  4689. .nohw2
  4690.     ENDC
  4691.  
  4692.     bsr    Enable
  4693.     move.l    d7,d0
  4694.     rts
  4695.  
  4696. Disable    tst.l    NoHW
  4697.     bne.b    .nohw
  4698.     jmp    (_LVODisable,a6)
  4699. .nohw    jmp    (_LVOForbid,a6)
  4700.  
  4701. Enable    tst.l    NoHW
  4702.     bne.b    .nohw
  4703.     jmp    (_LVOEnable,a6)
  4704. .nohw    jmp    (_LVOPermit,a6)
  4705.  
  4706.  
  4707.     CNOP    0,4
  4708. ChipTiming    tst.l    NoHW
  4709.     bne.b    .nohw1
  4710.  
  4711.     move.w    (intenar,a4),d7
  4712.     move.w    #$7FFF,(intena,a4)    Disable all interrupts
  4713.     or.w    #$8000,d7        set
  4714.     move.w    #$E000,(intena,a4)    Enable level6 ints
  4715.  
  4716.     bsr    GetVbr            Set new level 6 int
  4717.     lea    ($60+6*4,a0),a0
  4718.     move.l    (a0),-(sp)
  4719.     move.l    a0,-(sp)        Can be done 'cause we're in a disabled state!!
  4720.     lea    (Level6Trap,pc),a1    Otherwise should get vbr again on restore.
  4721.     move.l    a1,(a0)
  4722. .nohw1
  4723.  
  4724.     move.l    a5,a0
  4725.     moveq    #0,d0            No disable!
  4726.     bsr    RunNoMMU
  4727.  
  4728.     tst.l    NoHW
  4729.     bne.b    .nohw2
  4730.  
  4731.     move.l    (sp)+,a0        Restore old level 6 int
  4732.     move.l    (sp)+,(a0)
  4733.  
  4734.     move.w    #$7FFF,(intena,a4)    Disable all ints
  4735.     move.w    d7,(intena,a4)        Enable interrupts
  4736. .nohw2
  4737.  
  4738.     lea    CiaIntData,a0
  4739.     move.l    (a0),d0
  4740.     clr.l    (a0)
  4741.     not.l    d0
  4742.     rts
  4743.  
  4744.  
  4745.     CNOP    0,8
  4746. Level6Trap    movem.l    d0-d1/a0-a1,-(sp)
  4747.     move.b    CIAB+ciaicr,d0
  4748.     move.b    TimerBit+3,d1
  4749.     btst    d1,d0
  4750.     beq.b    .xit_argh
  4751.     lea    CiaIntData,a1
  4752.     bsr.b    CiaIntCode
  4753. .xit_argh    move.w    #INTF_EXTER,$DFF000+intreq
  4754.     movem.l    (sp)+,d0-d1/a0-a1
  4755.     nop                sync pipelines
  4756.     rte
  4757.  
  4758.  
  4759.     CNOP    0,8
  4760. CiaIntCode    subq.l    #1,(a1)            more loops to do?
  4761.     bne.b    .skip
  4762.     move.l    d4,(a1)            store result
  4763.     moveq    #1,d4            exit loop
  4764. .skip    rts
  4765.  
  4766.  
  4767. ; Loop to time CPU:
  4768.  
  4769.     CNOP    0,8
  4770. CPU_chiptiming    addq.l    #5,CiaIntData        Number of loops
  4771.     moveq    #-1,d4            Init counter
  4772.     move.b    #%00010101,(a2)        Start timer
  4773.     bra.b    .loop
  4774.     CNOP    0,8
  4775. .loop    subq.l    #1,d4            Main timing loop
  4776.     bne.b    .loop
  4777.     clr.b    (a2)            Stop timer
  4778.     rts
  4779.  
  4780. CPUTIMER_SIZEOF    EQU    (*-CPU_chiptiming+7)&-8
  4781.  
  4782. ; Loop to time FPU:
  4783.  
  4784.     CNOP    0,8
  4785. FPU_chiptiming    addq.l    #3,CiaIntData        Number of loops
  4786.     moveq    #-1,d4            Init counter
  4787.     fmove.x    #0.000000001,fp0
  4788.     fmove.x    fp0,fp1
  4789.  
  4790.     move.b    #%00010101,(a2)        Start timer
  4791.     bra.b    .loop
  4792.  
  4793.     CNOP    0,8
  4794. .loop    fadd.x    fp1,fp0            Main timing loop
  4795.     fsub.x    fp1,fp0
  4796.     subq.l    #1,d4
  4797.     bne.b    .loop
  4798.     clr.b    (a2)            Stop timer
  4799.     rts
  4800.  
  4801.  
  4802.  
  4803.     CNOP    0,4
  4804. getromver_novmem
  4805.     lea    (.novirtmempart,pc),a0
  4806.     moveq    #1,d0
  4807.     bra    RunNoMMU
  4808. ;;    bsr    RunNoMMU
  4809. ;;    rts
  4810.  
  4811. .novirtmempart
  4812.     lea    $1000000,a0
  4813.     tst.l    Phase5ID
  4814.     beq.b    .nophaserom
  4815.     lea    $0B80000,a1
  4816.     moveq    #8,d0
  4817.     swap    d0
  4818.     cmp.l    (-$14,a1),d0
  4819.     bne.b    .nophaserom
  4820.     neg.l    d0
  4821.     move.l    (a1,d0.l),d0
  4822.     and.l    #$FFF8FFFF,d0
  4823.     cmp.l    #$11104EF9,d0
  4824.     bne.b    .nophaserom
  4825.     move.l    a1,a0
  4826. .nophaserom
  4827.     move.l    (-$14,a0),d0
  4828.     move.l    d0,d1
  4829.     and.l    #$0003FFFF,d1
  4830.     bne.b    .no_rom
  4831.     cmp.l    #$00100000,d0
  4832.     bhi.b    .no_rom
  4833.     sub.l    d0,a0
  4834.     move.l    (a0),d1
  4835.     and.l    #$FFF8FFFF,d1
  4836.     cmp.l    #$11104EF9,d1
  4837.     bne.b    .no_rom
  4838.     move.l    (12,a0),d7
  4839.  
  4840.     bsr.b    ROMReSum
  4841.     move.l    d0,d6
  4842. .exit    rts
  4843. .no_rom    moveq    #0,d7
  4844.     moveq    #0,d6
  4845.     bra.b    .exit
  4846.  
  4847.  
  4848. ;  IN: d0=rom size, a0=rom start
  4849. ; OUT: d0=chksum
  4850. ROMReSum    move.l    d0,d1
  4851.     lsr.l    #3,d1
  4852.     move.l    -$18(a0,d0.l),d0
  4853.     not.l    d0
  4854. .loop    add.l    (a0)+,d0
  4855.     bcc.b    .skip1
  4856.     addq.l    #1,d0
  4857. .skip1    add.l    (a0)+,d0
  4858.     bcc.b    .skip2
  4859.     addq.l    #1,d0
  4860. .skip2    subq.l    #1,d1
  4861.     bne.b    .loop
  4862.     not.l    d0
  4863.     rts
  4864.  
  4865.  
  4866.     CNOP    0,4
  4867. ; a0=code to run without MMU, d0=disable flag
  4868. ; Code should be in Chip memory (in case of VMM or similar)
  4869. RunNoMMU    movem.l    d0/a5/a6,-(sp)
  4870.     move.l    (ExecBase02,pc),a6    Use (4).w??
  4871.     lea    (.super,pc),a5
  4872.     DBG    'RNM1'
  4873.     tst.l    d0
  4874.     beq.b    .nodis
  4875.     call    Disable
  4876. .nodis    tst.l    NoHW
  4877.     bne.b    .nohw1
  4878.     subq.l    #4,sp
  4879.     move.w    $DFF000+dmaconr,(sp)
  4880.     move.w    #$000F,$DFF000+dmacon
  4881.     or.w    #$8000,(sp)
  4882. .nohw1    call    Supervisor
  4883.     tst.l    NoHW
  4884.     bne.b    .nohw2
  4885.     move.w    (sp),$DFF000+dmacon
  4886.     addq.l    #4,sp
  4887. .nohw2    tst.l    (sp)+
  4888.     beq.b    .noen
  4889.     call    Enable
  4890. .noen    movem.l    (sp)+,a5/a6
  4891.     DBG    'RNM2'
  4892.     tst.l    d0
  4893.     rts
  4894.  
  4895.     CNOP    0,4
  4896. .super
  4897. ;;    or.w    #$700,sr
  4898.     tst.l    _MMUID
  4899.     beq.b    .nommua
  4900.     btst    #AFB_68040,_AttnFlags+1
  4901.     beq    .is030a
  4902.     bsr    _flush040
  4903.     move.l    d0,-(sp)
  4904.     movec    TC,d0
  4905.     move.l    d0,-(sp)
  4906.     movec    URP,d0
  4907.     move.l    d0,-(sp)
  4908.     movec    SRP,d0
  4909.     move.l    d0,-(sp)
  4910.     movec    DTT1,d0
  4911.     move.l    d0,-(sp)
  4912.     movec    DTT0,d0
  4913.     move.l    d0,-(sp)
  4914.     movec    ITT1,d0
  4915.     move.l    d0,-(sp)
  4916.     movec    ITT0,d0
  4917.     move.l    d0,-(sp)
  4918.     move.l    #$00FFC000,d0
  4919.     movec    d0,ITT0
  4920.     movec    d0,ITT1
  4921.     movec    d0,DTT1
  4922.     move.l    #$0000C040,d0
  4923.     movec    d0,DTT0
  4924.     move.l    #$00030000,d0
  4925.     movec    d0,URP
  4926.     movec    d0,SRP
  4927.     moveq    #0,d0
  4928.     movec    d0,TC
  4929.     bsr    _flush040
  4930.     move.l    (7*4,sp),d0
  4931. .nommua    jsr    (a0)
  4932.     tst.l    _MMUID
  4933.     beq.b    .nommub
  4934.     btst    #AFB_68040,_AttnFlags+1
  4935.     beq.b    .is030b
  4936.     bsr    _flush040
  4937.     move.l    d0,-(sp)
  4938.     move.l    (1*4,sp),d0
  4939.     movec    d0,ITT0
  4940.     move.l    (2*4,sp),d0
  4941.     movec    d0,ITT1
  4942.     move.l    (3*4,sp),d0
  4943.     movec    d0,DTT0
  4944.     move.l    (4*4,sp),d0
  4945.     movec    d0,DTT1
  4946.     move.l    (5*4,sp),d0
  4947.     movec    d0,SRP
  4948.     move.l    (6*4,sp),d0
  4949.     movec    d0,URP
  4950.     bsr    _flush040
  4951.     move.l    (7*4,sp),d0
  4952.     movec    d0,TC
  4953.     move.l    (sp)+,d0
  4954.     lea    (7*4,sp),sp
  4955. .nommub2    addq.l    #4,sp
  4956. .nommub    nop                sync pipelines
  4957.     rte
  4958.  
  4959. .is030a    clr.l    -(sp)
  4960.     pmove.l    tc,(sp)
  4961.     move.l    (sp),-(sp)
  4962.     bclr    #7,(sp)
  4963.     pmove.l    (sp),tc
  4964.     addq.l    #4,sp
  4965.     bra.b    .nommua
  4966.  
  4967. .is030b    pmove.l    (sp),tc
  4968.     bra.b    .nommub2
  4969.  
  4970.  
  4971. _flush040    dc.w    $F518        ; PFLUSHA    flush the address translation cache
  4972.     dc.w    $F4F8        ; CPUSHA BC    flush the caches into memory
  4973.     dc.w    $F4D8        ; INVA    BC    invalidate the data and inst caches
  4974.     rts
  4975.  
  4976.  
  4977.     CNOP    0,4
  4978. ; OUT: d0=0 no mmu, d0=1 68851 mmu, d0=2 68030 MMU, d0=3 68040 MMU, d0=4 68060 MMU
  4979. ;      d1=mmu activity status, valid if d0>0
  4980. GetMMU
  4981. ; Must be called from user state!!
  4982. ;  OUT: d0=success if working MMU exists, null otherwise
  4983. ;       d0=0 for no MMU
  4984. ;          4 for 68060 or 68LC060 internal MMU
  4985. ;          3 for 68040 or 68LC040 internal MMU
  4986. ;          2 for 68030 internal MMU
  4987. ;          1 for 68020 + 68851 MMU
  4988. ;       d1=mmu activity status, valid if d0>0
  4989. TestForMMU    movem.l    d2-a6,-(sp)
  4990.     moveq    #0,d7
  4991.  
  4992.     move.l    (ExecBase02,pc),a6
  4993.     move.w    _AttnFlags,d0
  4994.     btst    #AFB_68020,d0        No MMU below 68020!
  4995.     beq.b    .exit
  4996.     cmp.w    #37,(LIB_VERSION,a6)
  4997.     blo.b    .oldtest
  4998.     lea    (.test040plus,pc),a5
  4999.     moveq    #MC68060m,d6
  5000.     tst.b    d0            Test #AFB_68060
  5001.     bmi.b    .test
  5002.     subq.l    #1,d6
  5003.     btst    #AFB_68040,d0
  5004.     bne.b    .test
  5005. .otcont    lea    (.test020plus,pc),a5
  5006.     subq.l    #1,d6
  5007.     btst    #AFB_68030,d0
  5008.     bne.b    .test
  5009.     subq.l    #1,d6
  5010. .test
  5011.     DBG    'MMU1'
  5012.     jsr    (a5)
  5013.     DBG    'MMU2'
  5014.  
  5015. .exit    move.l    d7,d0
  5016.     beq.b    .fail
  5017.     move.l    d6,d0
  5018. .fail    movem.l    (sp)+,d2-a6
  5019.     rts
  5020.  
  5021. .oldtest    moveq    #MC68030m+1,d6
  5022.     bra.b    .otcont
  5023.  
  5024. .test040plus    lea    (.gogo040,pc),a5
  5025.     call    Disable
  5026.     call    Supervisor
  5027.     jmp    (_LVOEnable,a6)
  5028. .gogo040    or.w    #$700,sr        Disable interrupts.
  5029.     movec    vbr,a0            Get VBR
  5030.     move.l    ($10,a0),-(sp)        Save Illegal Instruction vector
  5031.     move.l    ($2C,a0),-(sp)        Save F-Line Emul vector
  5032.     move.l    a0,-(sp)        Save VBR
  5033.  
  5034.     lea    (.illegal040,pc),a1
  5035.     move.l    a1,($10,a0)
  5036.     move.l    a1,($2C,a0)
  5037.     bsr    _flush040
  5038.  
  5039.     moveq    #0,d0            IMPORTANT!
  5040.     moveq    #-1,d7
  5041.     movec    tc,d0            $4e7a0003    Test some "common" MMU regs:
  5042.     movec    urp,d1            $4e7a1806    Test 040/060 MMU only reg!!
  5043.     movec    srp,d1            $4e7a1807
  5044. .exit040    nop
  5045.     nop
  5046.     ; d0=mmu TC (or null)
  5047.  
  5048.     moveq    #0,d1
  5049.     tst.l    d7
  5050.     beq.b    .gm4_nommu
  5051.     btst    #15,d0            Bit 15: On/Off!!
  5052.     beq.b    .gm4_nommu
  5053.     moveq    #1,d1
  5054. .gm4_nommu
  5055.     move.l    (sp)+,a0
  5056.     move.l    (sp)+,($2C,a0)        Restore F-Line Emul vector
  5057.     move.l    (sp)+,($10,a0)        Restore Illegal Instruction vector
  5058.     bsr    _flush040
  5059.     nop                sync pipelines
  5060.     rte
  5061.  
  5062.     CNOP    0,4
  5063. .illegal040    moveq    #0,d7
  5064.     lea    (.exit040,pc),a0
  5065.     move.l    a0,(2,sp)
  5066.     bsr    _flush040
  5067.     nop                sync pipelines
  5068.     rte
  5069.  
  5070.  
  5071. .simpletest    call    Disable
  5072.     lea    (.gogos020,pc),a5
  5073.     call    Supervisor
  5074.     jmp    (_LVOEnable,a6)
  5075.  
  5076. .gogos020    or.w    #$700,sr        Disable interrupts.
  5077.  
  5078.     movec    vbr,a0            Get VBR
  5079.     move.l    ($10,a0),-(sp)        Save Illegal Instruction vector
  5080.     move.l    ($2C,a0),-(sp)        Save F-Line Emul vector
  5081.     move.l    a0,-(sp)        Save VBR
  5082.  
  5083.     lea    (.mmuinstfailures,pc),a1
  5084.     move.l    a1,($10,a0)
  5085.     move.l    a1,($2C,a0)
  5086.  
  5087.     bsr    _flush020
  5088.  
  5089.     moveq    #-1,d7
  5090.     clr.l    -(sp)
  5091.     pmove.l    tc,(sp)
  5092. .exitsupers    move.l    (sp)+,d5
  5093.  
  5094.     moveq    #0,d1
  5095.     tst.l    d7
  5096.     beq.b    .gm2_nommus
  5097.     tst.l    d5            Bit 31: On/Off!!
  5098.     bpl.b    .gm2_nommus
  5099.     moveq    #1,d1
  5100. .gm2_nommus
  5101.     move.l    (sp)+,a0        Restore VBR
  5102.     move.l    (sp)+,($2C,a0)        Restore F-Line Emul vector
  5103.     move.l    (sp)+,($10,a0)        Restore Illegal Instruction vector
  5104.     bsr    _flush020
  5105.     rte
  5106.  
  5107. .mmuinstfailures
  5108.     lea    (.exitsupers,pc),a0    Invalid mmu instruction!
  5109.     moveq    #0,d7
  5110.     move.l    a0,(2,sp)
  5111.     rte
  5112.  
  5113.  
  5114.  
  5115. .test020plus
  5116. ;;GVP's    move.l    #$07E1<<16!$FFFF,d0    Try to find any 'Great Valley Products' board
  5117. ;;works    jsr    FindConfigDev
  5118. ;;now??    bne.b    .simpletest        If found test MMU with simple code (following one crashes!)
  5119.  
  5120.     lea    $D0000000,a2
  5121.     move.w    #$10000000/(512*1024)-1-1,d2
  5122. .tloop    move.l    a2,a1
  5123.     call    TypeOfMem
  5124.     tst.l    d0
  5125.     bne    .simpletest
  5126.     add.l    #512*1024,a2
  5127.     dbf    d2,.tloop
  5128.  
  5129.     move.l    #((1<<8)+.TTable1End-.TTable1),d0
  5130.     moveq    #MEMF_PUBLIC,d1
  5131.     call    AllocMem
  5132.     tst.l    d0
  5133.     beq    .simpletest
  5134.     move.l    d0,a4
  5135.  
  5136.     add.l    #(1<<7)-1,d0
  5137.     and.w    #-(1<<7),d0
  5138.     move.l    d0,a2
  5139.     lea    (.TTable1,pc),a0
  5140.     move.l    a2,a1
  5141.     moveq    #(.TTable1End-.TTable1),d0
  5142.     call    CopyMem            Used to use CopyMemQuick... Is it KS1.3+?
  5143.  
  5144.     call    Disable
  5145.     lea    (.gogo020,pc),a5
  5146.     call    Supervisor
  5147.     call    Enable
  5148.  
  5149.     movem.l    d0-d1,-(sp)
  5150.     move.l    #((1<<8)+.TTable1End-.TTable1),d0
  5151.     move.l    a4,a1
  5152.     call    FreeMem
  5153.     movem.l    (sp)+,d0-d1
  5154.     rts
  5155.  
  5156. .gogo020    or.w    #$700,sr        Disable interrupts.
  5157.     moveq    #0,d5            IMPORTANT!
  5158.  
  5159.     move.l    #$D0000000,d0        Test for our usage of area $D0000000:
  5160.     move.l    #$F0000000,d1
  5161.     move.l    sp,d2            SSP uses $D0000000?
  5162.     and.l    d1,d2
  5163.     cmp.l    d0,d2
  5164.     beq    .exitall
  5165.     move.l    #.test020plus,d2    PC?
  5166.     and.l    d1,d2
  5167.     cmp.l    d0,d2
  5168.     beq    .exitall
  5169.  
  5170.     movec    vbr,a0            Get VBR
  5171.     move.l    ($08,a0),-(sp)        Save Access Fault vector
  5172.     move.l    ($10,a0),-(sp)        Save Illegal Instruction vector
  5173.     move.l    ($2C,a0),-(sp)        Save F-Line Emul vector
  5174.     move.l    ($E0,a0),-(sp)        Save MMU Config Error vector
  5175.     move.l    ($E4,a0),-(sp)        Save MMU Illegal Operation Error vector
  5176.     move.l    ($E8,a0),-(sp)        Save MMU Access Level Violation Error vector
  5177.     move.l    a0,-(sp)        Save VBR
  5178.  
  5179.     subq.l    #8,sp
  5180.  
  5181.     lea    (.mmufailure_es,pc),a1    Set new vectors:
  5182.     move.l    a1,($08,a0)
  5183.     move.l    a1,($10,a0)
  5184.     move.l    a1,($2C,a0)
  5185.     move.l    a1,($E0,a0)
  5186.     move.l    a1,($E4,a0)
  5187.     move.l    a1,($E8,a0)
  5188.  
  5189.     bsr    _flush020
  5190.  
  5191.     pmove.l    tc,(sp)            Save tc:
  5192.     moveq    #-1,d7
  5193.     move.l    (sp),d5
  5194.     bmi    .exitsuper        MMU in use!
  5195.     moveq    #0,d7
  5196.  
  5197.     dc.w    $F017,$4E00        pmove.q    crp,(sp)
  5198.     move.l    (sp),d3            Save crp:
  5199.     move.l    (4,sp),d4
  5200.  
  5201.     lea    (.mmufailure,pc),a1
  5202.     move.l    a1,($08,a0)
  5203.     move.l    a1,($10,a0)
  5204.     move.l    a1,($2C,a0)
  5205.     move.l    a1,($E0,a0)
  5206.     move.l    a1,($E4,a0)
  5207.     move.l    a1,($E8,a0)
  5208.  
  5209.     bsr    _flush020
  5210.  
  5211.     clr.l    (sp)            Clear translation control register
  5212.     pmove.l    (sp),tc
  5213.     nop
  5214.  
  5215.     move.l    #$80000002,(sp)        Set our crp: (was: 202)
  5216.     move.l    a2,(4,sp)
  5217.     dc.w    $F017,$4C00        pmove.q (sp),crp
  5218.  
  5219.     move.l    #$80D04780,(sp)        Enable mmu mapping:
  5220.     pmove.l    (sp),tc
  5221.  
  5222.     bsr    _flush020
  5223.  
  5224.     clr.b    (.TTableD-.TTable1,a2)    Make it map to address 0.
  5225.     bsr    _flush020
  5226.  
  5227.     lea    (.chipaddr,pc),a3    Test memory mapping a bit... :)
  5228.     move.l    a3,d0            (This should _finally_ catch
  5229.     or.l    #$D0000000,d0        nonfunctional 030 MMU)
  5230.     move.l    d0,a1
  5231.     move.l    #'MMUt',d0
  5232.     move.l    d0,(a3)
  5233.     nop
  5234.     cmp.l    (a1),d0
  5235.     bne.b    .remove
  5236.     not.l    d0            Test write mapping:
  5237.     move.l    (a1),-(sp)
  5238.     move.l    d0,(a1)
  5239.     nop
  5240.     move.l    (a3),d1
  5241.     move.l    (sp)+,(a1)
  5242.     cmp.l    d1,d0
  5243.     bne.b    .remove
  5244.     clr.l    (a3)
  5245.     nop
  5246.     tst.l    (a1)
  5247.     bne.b    .remove
  5248.  
  5249.  
  5250.     ;move.l    sp,$200.w        debug
  5251.  
  5252.     move.l    #$D0000060,(.TTableD-.TTable1,a2) Make it invalid
  5253.     bsr    _flush020
  5254.     nop                Sync pipelines
  5255.     move.l    a0,a1
  5256.     lea    $DFFFFFFC,a0        Test memory (in)validity:
  5257.     dc.w    $F010,$9C15        ptestw    #5,(a0),#7
  5258.     dc.w    $F017,$6200        pmove.w    mmusr,(sp)
  5259.     move.w    (sp),d0
  5260.     btst    #10,d0
  5261.     beq.b    .remove            Memory isn't invalid!!
  5262.  
  5263.     lea    (.busfailure,pc),a2
  5264.     move.l    a2,($08,a1)
  5265.  
  5266.     bsr    _flush020
  5267.  
  5268.     move.l    (a0),d0            Cause bus failure.
  5269. .busfproceed
  5270. .remove
  5271. .restoremmu    clr.l    (sp)            Disable mapping:
  5272.     pmove.l    (sp),tc
  5273.     nop
  5274.  
  5275.     move.l    d3,(sp)            Restore crp:
  5276.     move.l    d4,(4,sp)
  5277.     dc.w    $F017,$4C00        pmove.q (sp),crp
  5278.  
  5279.     move.l    d5,(sp)            Restore tc:
  5280.     pmove.l    (sp),tc
  5281.  
  5282.     ;move.l    #'rest',($200).w    debug
  5283.     ;move.l    d5,($204).w
  5284.  
  5285. .exitsuper    addq.l    #8,sp
  5286.  
  5287.     moveq    #0,d1
  5288.     tst.l    d7
  5289.     beq.b    .gm2_nommu
  5290.     tst.l    d5            Bit 31: On/Off!!
  5291.     bpl.b    .gm2_nommu
  5292.     moveq    #1,d1
  5293. .gm2_nommu
  5294.     move.l    (sp)+,a0        Restore VBR
  5295.     move.l    (sp)+,($E8,a0)        Restore MMU Access Level Violation Error vector
  5296.     move.l    (sp)+,($E4,a0)        Restore MMU Illegal Operation vector
  5297.     move.l    (sp)+,($E0,a0)        Restore MMU Config Error vector
  5298.     move.l    (sp)+,($2C,a0)        Restore F-Line Emul vector
  5299.     move.l    (sp)+,($10,a0)        Restore Illegal Instruction vector
  5300.     move.l    (sp)+,($08,a0)        Restore Access Fault vector
  5301. .exitall    bsr    _flush020
  5302.     rte
  5303.  
  5304. .mmufailure    lea    (.restoremmu,pc),a0    Invalid mmu table!?
  5305. .exitrt    moveq    #0,d7
  5306. .exitrt2    move.l    a0,(2,sp)
  5307. .be_exitrte    rte
  5308.  
  5309. .mmufailure_es    lea    (.exitsuper,pc),a0    Invalid mmu instruction!
  5310.     bra.b    .exitrt
  5311.  
  5312. .busfailure    bclr    #0,(10,sp)
  5313.     beq.b    .be_exitrte
  5314.     moveq    #-1,d7
  5315.     lea    (.busfproceed,pc),a0
  5316.     bra.b    .exitrt2
  5317.  
  5318.  
  5319. ; Pagesize is 8K (=1<<%1101)
  5320. ; Initial shift is 0 (%0000)
  5321. ; TIA is 4 (%0100)  [$10000000<<4=$100000000]
  5322. ; TIB is 7 (%0111)  [$00200000<<7=$10000000]
  5323. ; TIC is 8 (%1000)  [$00002000<<8=$00200000]
  5324. ; TID is 0 (%0000)
  5325. ;  TC = $80D04780
  5326. ; CRP = $80000002 TranslationTable
  5327.  
  5328.     CNOP    0,4
  5329. .TTable1    dc.l    $00000061,$10000061,$20000061,$30000061
  5330.     dc.l    $40000061,$50000061,$60000061,$70000061
  5331.     dc.l    $80000061,$90000061,$A0000061,$B0000061
  5332.     dc.l    $C0000061
  5333. .TTableD    dc.l    $D0000061
  5334.     dc.l    $E0000061,$F0000061
  5335. .TTable1End
  5336. .chipaddr    dc.l    0
  5337.  
  5338. _flush020    move.l    d0,-(sp)
  5339.     movec    cacr,d0
  5340.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  5341.     movec    d0,cacr
  5342.     move.l    (sp)+,d0
  5343.     rts
  5344.  
  5345.  
  5346.  
  5347.     CNOP    0,4
  5348. ;;    SECTION    BSS_C,BSS_C    Our megademo uses great chip-buffers :-)
  5349.  
  5350. ;;ExecBase03    ds.l    1
  5351.  
  5352. NoHW    ds.l    1
  5353. _MMUID    ds.l    1
  5354. TimerBit    ds.l    1
  5355. TimerMask    ds.l    1
  5356. CiabResource    ds.l    1
  5357. CiaIntData    ds.l    1
  5358. _GfxBase    ds.l    1
  5359.     ds.l    0    Align
  5360. _AttnFlags    ds.w    1
  5361.  
  5362. AddrChipData    ds.l    4    16 bytes
  5363.  
  5364.     END
  5365.